NSMutableDictionary 未写入文件
我有 NSMutableDictionary 对象,例如 obj
。当我使用将其写入磁盘时 [obj writeToFile:filenameatomically:YES]
,文件不会写入磁盘。但同一组语句适用于较小的可变字典。
第一个obj
是类的(nonatomic,retain)
属性对象。第二个较小的 obj 是临时局部变量。
I have NSMutableDictionary object say obj
. When I write it to the disk using[obj writeToFile:filename atomically:YES]
, the file does not get written to the disk. But the same set of statements work for a smaller mutable dictionary.
The first obj
is (nonatomic, retain)
property object of a class. The second smaller obj
is a temporary local variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这敲响了警钟。也就是说,当您尝试将大字典写入磁盘时,里面有什么?如果您使用任何 NSDictionary 的文件写入方法,它们将仅适用于仅包含适合在属性列表中使用的类实例的字典。
也就是说,如果其中有随机的其他类,则不会写入字典。类是否支持 NSCoding 并不重要。
如果您需要保留具有非属性列表类的字典,则需要使用 NSCoding,或者更可能更好的是使用 Core Data。
That sets off a warning bell. Namely, when you are attempting to write the large dictionary to disk, what is in it? If you are using any of NSDictionary's file writing methods, they will only work with dictionaries that only contain instances of the classes blessed for use in property lists.
That is, if you have random other classes in there, the dictionary will not be written. Doesn't matter of the classes support NSCoding or not.
If you need to persist a dictionary with non-property list classes, you'll either need to use NSCoding or, more likely better, use Core Data.
这应该有效。您是否偶然检查过
obj
不是nil
?This should work. Have you checked that
obj
isn'tnil
by some accident?