首先是NSString
1.NSString 转换成NSData 对象
NSData* xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding];
2.NSData 转换成NSString对象
NSData * data;
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
然后NSDictionary和NSArray以及所有遵循<NSCoding>协议的对象
1.写入(XXX代表任意对象遵循<NSCoding>协议) XXX转为NSData
id XXX;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:XXX];
[data writeToFile:[Utils applicationDocumentsDirectory:kCollectFilePath] atomically:YES];
2.转换
id XXX= [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:[Utils applicationDocumentsDirectory:kCollectFilePath]]];
其实我只是突然想试试怎么转NSData, 忘了归档接档,所以转成NSData也是非常容易的