300K大小的NSDictionary类型数据用什么方式实现数据持久化比较合适?

如题。

我用writeToFile写入到文件好像失败了。单纯用一个简单的NSDictionary都没问题。300K,数据莫名其妙没写进。

阅读 3.2k
2 个回答

首先
writeToFile失败不是大小的问题,肯定是字典里有不合法的对象了,那么哪些是不合法呢?
文档里有有这么一句话

Discussion
This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns NO if all the objects are not property list objects, since the resultant file would not be a valid property list.

所以...
例如你可以试试

 [@{@"k":[NSNull null]} writeToFile:@"xxx" atomically:YES];

然后回到另一个问题,什么方案合适,我推荐用: EGOCache

是否存放了非系统类型的对象?

如果是,需要实现 NSCoding 协议再进行归档。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题