Convert the UTF 8 encoded NSData to string in swift and objective c
Solution:
Use the below technics to convert the UTF 8 NsData to string in objective code swift.
Objective c:
Method 1:
Swift:
Method 1:
Use the below technics to convert the UTF 8 NsData to string in objective code swift.
Objective c:
Method 1:
NSString* Str = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
Method 2:
NSString* Str = [NSString stringWithUTF8String:[theData bytes]];
Swift:
Method 1:
let Str = String(data: data, encoding: .utf8)
Method 2:
let Str = String(data: data.subdata(in: 0 ..< data.count - 1), encoding: .utf8)
Method 3:
let Str = data.withUnsafeBytes(String.init(utf8String:))
Comments
Post a Comment