标签:
这里,将字典转换成NSData类型。有一点必须注意的,必须实现
- (id)initWithCoder:(NSCoder *)aDecoder方法和
- (void)encodeWithCoder:(NSCoder *)aCoder方法。
+ (NSData *)returnDataWithDictionary:(NSDictionary*)dict
{
NSMutableData* data = [[NSMutableData alloc]init];
NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
[archiver encodeObject:dict forKey:@"talkData"];
[archiver finishEncoding];
return data;
}
将字典路径的字符串转换为字典
+ (NSDictionary *)returnDictionaryWithDataPath:(NSString*)path
{
NSData* data = [[NSMutableData alloc]initWithContentsOfFile:path];
NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:data];
NSDictionary* myDictionary = [unarchiver decodeObjectForKey:@"talkData"];
[unarchiver finishDecoding];
return myDictionary;
}
标签:
原文地址:http://www.cnblogs.com/XHShare/p/4973193.html