Objective-C
You can use (see NSString Class Reference)
- (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding
Example:
NSString *myString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
Remark: Please notice the NSData
value must be valid for the encoding specified (UTF-8 in the example above), otherwise nil
will be returned:
Prior Swift 3.0
String(data: yourData, encoding: NSUTF8StringEncoding)
Swift 3.0 Onwards
String(data: yourData, encoding: .utf8)