Cocoa provides four mechanisms to store data persistently on iOS:
1 NSUserdefaults
It is mainly used to store short information, such as application settings, attributes, and user data.
2. attribute list
Store data on a disk in the form of a list. The attribute list class includes NSArray, NSDictionary, NSString, NSNumber, NSDate, and NSdata.
These types of data can be stored to the disk and read from the disk by directly calling writeToFile and corresponding loading functions.
The corresponding loading functions include:
ArrayWithContentsOfFile:
DictionaryWithContentsOfFile:
StringWithContentsOfFile:
DataWithContentsOfFile:
NSdate and NSNumber can be stored after being replaced with NSString.
3. Object Archiving
For data that cannot be simply represented by attribute lists, object archive is used for storage.
Using NSCopying and implementing two functions: encodeWithCoder and initWithCoder, you can replace this type of object
NSData, and then use the 2nd method to store and read data.
4 CoreData
A persistence tool provided by Apple. To use this method, first we need to create a data model, and then we can easily
To store and read objects, and all others are handed over to the system.