iOS Persistent storage

Source: Internet
Author: User

How to persist data on iOS systems, Cocoa provides 4 mechanisms:
1 nsuserdefaults
It is used primarily to store short information, such as application settings and attributes, and user data.
2 List of properties
Store the data on disk as a list. The property list classes include Nsarray, Nsdictionary, NSString, NSNumber, NSDate, NSData.
These types of data can be directly called WriteToFile and the corresponding load function to be stored to disk and read out from disk.
The corresponding load functions are:
Arraywithcontentsoffile:
Dictionarywithcontentsoffile:
Stringwithcontentsoffile:
Datawithcontentsoffile:
NSDate and NSNumber can be stored after replacing with NSString.
3 Object Archiving
For those data that cannot be simply represented by a property list, the object archive is used to store it.
By using nscopying and implementing the two functions Encodewithcoder and initwithcoder, it is possible to replace such objects with
NSData, then use the 2nd method to store and read.
4 CoreData
A persistent tool provided by Apple. Using this method is, first we have to build a data model, and then we can easily
The storage and reading of the object, the other all to a system.

iOS Persistent storage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.