Objective-C:
NSString to NSData:
NSString* str= @"string";
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
NSData to NSString:
NSString* newStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
Swift:
Строка для данных:
var testString = "string"
var somedata = testString.data(using: String.Encoding.utf8)
Данные в строку:
var backToString = String(data: somedata!, encoding: String.Encoding.utf8) as String!