NSDictionary writeToFile [英] NSDictionary writeToFile

查看:65
本文介绍了NSDictionary writeToFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保存字典有大小限制吗?

Is there a size limit to saving dictionaries?

我正在尝试使用 writeToFile: 编写一个包含大约 100 个键的相当大的字典,其中包含嵌套字典:但它从不写入并且始终为 false.

I am attempting to write a rather large dictionary with around 100 keys with nested dictionaries using writeToFile: but it never writes and is always false.

这是限制还是我做错了什么,

Is this a limitation or am I doing something incorrect,

我使用的代码如下.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *fullPath = [documentsDir stringByAppendingPathComponent:@"test.plist"];   

[myDict writeToFile: fullPath  atomically:YES];

推荐答案

没有大小限制(内存和磁盘空间除外).

There is no size limit (save for memory and disk space).

myDict 的内容是什么?

如果它不是属性列表中允许的一小组类,那么您不能使用writeToFile:atomically:.

If it is anything but the small set of classes allowed in property lists, then you can't use writeToFile:atomically:.

要么您需要将字典限制为仅包含这些类的实例要么您将需要使用不同的归档方法.

Either you would need to limit your dictionary to only containing instances of those classes or you will need to use a different archiving method.

特别是,许多 JSON 库会将 NSNULL 实例喷入集合中.那些不能存档.您需要将它们编辑掉或用可以存档的对象替换它们.

In particular, a lot of the JSON libraries will spew NSNULL instances into the collections. Those can't be archived. You need to either edit them out or replace them with objects that can be archived.

相关性:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i

这篇关于NSDictionary writeToFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆