简体   繁体   English

NSKeyedArchiver或[NSArray writeToFile:atomically:]?

[英]NSKeyedArchiver or [NSArray writeToFile:atomically:]?

Well I just saved the same data twice and using NSKeyedArchiver the file was about 30KB bigger (from 60KB to 90KB) I know its not much but I'm going to have more of these files and some will be bigger than others. 好吧,我刚刚保存了两次相同的数据并使用NSKeyedArchiver,文件大约30KB(从60KB到90KB)我知道它不多,但我会有更多的这些文件,有些将比其他文件更大。 So whats the difference and what are the advantage of using one of the other? 那么差异是什么,使用另一个的优势是什么?

You can stick to -[NSArray writeToFile:atomically:] for simple objects, ie, the ones natively supported by property lists (essentially strings, numbers, dates, byte sequences, as well as arrays and dictionaries). 你可以坚持 - [NSArray writeToFile:atomically:]用于简单对象,即属性列表本身支持的对象(主要是字符串,数字,日期,字节序列,以及数组和字典)。

NSKeyedArchiver would be preferred/necessary over NSArray/NSDictionary if you're storing complex data. 如果您要存储复杂数据,NSKeyedArchiver将优先于NSArray / NSDictionary。 As opposed to the property lists created by NSArray or NSDictionary, a keyed archive contains metadata about a whole object graph hierarchy — objects, their identities, their relationships, classes, instance variables, superclasses. 与NSArray或NSDictionary创建的属性列表相反,键控存档包含有关整个对象图层次结构的元数据 - 对象,它们的标识,它们的关系,类,实例变量,超类。 Data is keyed, which can be used to maintain forward or backward compatibility by means of ignoring keys (eg instance variables). 数据是键控的,可以通过忽略键(例如实例变量)来保持向前或向后兼容性。 More information on (keyed) archives is available at the Archives and Serializations Programming Guide . 有关(键控)存档的更多信息,请参阅“ 存档和序列化编程指南”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM