1、Property Lists
属性列表,扩展名为plist。
- Property list有三种存储方式:XML, binary format, “old-style” ASCII format inherited from OpenStep。old-style format的序列化API是只读的。
A property list can be stored in one of three different ways: in an XML representation, in a binary format, or in an “old-style” ASCII format inherited from OpenStep. You can serialize property lists in the XML and binary formats. The serialization API with the old-style format is read-only.
- 数据大小限制(几百kb内)
For situations where you need to store small amounts of persistent data—say less than a few hundred kilobytes—property lists offer a uniform and convenient means of organizing, storing, and accessing the data.
In some situations, the property-list architecture may prove insufficient. If you need a way to store large, complex graphs of objects, objects not supported by the property-list architecture, or objects whose mutability settings must be retained, use archiving.
-
如果我们的对象全由NSDictionary, NSArray, NSString, NSDate, NSData, 或NSNumber类派生,我们可以创建property list。
-
XML property list 比 binary 格式的可移植性好,可以手动编辑,但是binary property lists 兼容性好,需要的存储空间少,读写速度要优于XML property lists。通常来说,如果你的property list相对较小,XML property lists的优点会战胜它相对binary property lists的I/O速度,难兼容的缺点。
-
如果你有大量数据,binary property lists, keyed archives,或自定义数据格式会是更好的解决方案。
2、NSUserDefaults
-
NSUserDefaults,提供了与默认系统交互的程序接口。
-
默认系统允许应用去自定义它的行为来符合用户的偏好。所以它主要是用来存储配置信息。
-
支持的数据类型有:floats,doubles,integers,Booleans,URLs,NSData,NSString,NSNumber,NSDate,NSArray和NSDictionary。如果还想存储其他类型的对象,需要使用NSData对它们进行归档。
-
事实上,NSUserDefaults就是把数据保存在property list中
3、Archive
Archives provide a means to convert objects and values into an architecture-independent stream of bytes that preserves the identity of and the relationships between the objects and values.
-
如果对象是NSString、NSDictionary、NSArray、NSData、NSNumber等类型,可以直接用NSKeyedArchiver进行归档和恢复。
-
不是所有的对象都可以直接用这种方法进行归档,只有遵守了NSCoding协议的对象才可以。
3、DB
数据库可以提供对数据更加高级的操作,这是其他方式不能提供的。当涉及到建模,查询,遍历,持久化复杂的对象图,就可以采用数据库来实现数据持久化。
- SQLite
- Core Data
- FMDB
网友评论