标签:style color io ar for sp 文件 on cti
我封装好了2个方法,用来字典和data相互转换的,直接复制方法拿来用就可以了,注意2点:
1.我是用的mrc,用arc的同学把autorelease去掉即可。
2.第二个我是路径文件转的字典,想data转的话自己把方法改一下就行了。
//字典转data
+(NSData *)returnDataWithDictionary:(NSDictionary *)dict
{
NSMutableData * data = [[NSMutableData alloc] init];
NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:dict forKey:@"talkData"];
[archiver finishEncoding];
[data autorelease];
[archiver autorelease];
return data;
}
//路径文件转dictonary
+(NSDictionary *)returnDictionaryWithDataPath:(NSString *)path
{
NSData * data = [[NSMutableData alloc] initWithContentsOfFile:path];
NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary * myDictionary = [[unarchiver decodeObjectForKey:@"talkData"] retain];
[unarchiver finishDecoding];
// NSLog(@"%@", myDictionary);
[unarchiver autorelease];
[data autorelease];
return myDictionary;
}
标签:style color io ar for sp 文件 on cti
原文地址:http://blog.csdn.net/miaocuilin/article/details/40210281