ググればすぐ出てくるけどよく忘れるのでメモ。
カテゴリとして実装し、asData
やasUTF8String
などを生やして使うのが楽かも知れない。
NSData to NSString
NSString *string = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSString to NSData
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
参考
- Convert UTF-8 encoded NSData to NSString カテゴリ実装するアイデア良さそう
- NSData と NSString の相互変換