4 ways to persist IOS data

Source: Internet
Author: User
Tags tmp file

iOS 4 a system mechanism for persisting data storage to iOS files:

    1. Attribute list (nsuserdefaults, plist file)
    2. Object Archive (nscoding)
    3. iOS embedded relational database (SQLite3)
    4. Apple-provided persistence tool (Core Data)

It says that data persistence involves a common element. Since the data is persisted to the iOS file system, the application sandbox has long been involved .

You can try using Xcode to create an empty app, and then open the app catalog to see the following files

1, Documents① storage content We can save the application's data file in this directory. However, these data types are limited to non-renewable data, and renewable data files should be stored in the Library/cache directory. Whether ② will be synced by itunes is 2, Documents/inbox① store content This directory is used to save files opened by external apps requesting the current application. For example, our application is called a, several open file formats are registered to the system, B is applied with a file F in a supported format, and application call a opens F. Since F is currently in the sandbox of the B application, we know that the sandbox mechanism is not allowed A to access the files in the B sandbox, so Apple's solution is to speak F copy a copy of the Documents/inbox directory to the A application, and then let a open f. ② if itunes sync is 3, Library① store content Apple recommends storing the default settings or other status information. ② will be synced with itunes Yes, but in addition to the Caches subdirectory 4, Library/caches① storage content is mainly cached files, the user in the process of the cache can be saved in this directory. As mentioned earlier, the documents directory is used to store non-renewable files, so this directory is used to hold those renewable files, such as data requested by the network. For this reason, the application usually also needs to be responsible for deleting these files. Whether the ② will be synced by itunes No. 5, Library/preferences① Store the content application preferences file. The settings data we write with Nsuserdefaults will be saved to a plist file in that directory, which is called Write Plist! ② will be synced by itunes is 6, Tmp① store the contents of various temporary files, save the app when you start the files that are not needed. Moreover, when the application no longer needs these files should be actively deleted, because the contents of the directory can be removed from the system at any time, the current known one possible reason is that the system disk storage space is insufficient. Whether ② will be synced by itunes No
    // Sandbox Catalog     nshomedirectory ();         // tmp file path     nstemporarydirectory ();         // Document    Nsarray *paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES);     *path = [Paths Objectatindex:0];

4 ways to persist IOS data

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.