NSData与NSString互转
//
// main.m
// NSData
//
// Created by hhg on 15-6-11.
// Copyright (c) 2015年 hhg. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *string = @"hhg ";
//string---> data
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", data);
//data ---> string
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", myString);
}
return 0;
}