iOS data persistence

Source: Internet
Author: User

There are two types of data storage: memory and Flash. Memory storage is temporary, run-time efficient, but efficient, while Flash is a persistent storage, but produces I/O consumption, the efficiency is relatively low.

Archive: Transfer memory data to flash for persistent operation.

Common data storage scenarios:

1) nsuserdefaults, for storing configuration information

Nsuserdefaults is designed to store configuration information for devices and applications, and it returns the default, and most commonly used, instance objects through a factory method. This object stores the configuration information of the user in the system, which can be modified by the instance object, or the new configuration items can be created according to their own requirements.

2) SQLite, used to store more data for query requirements

Generally speaking, the formatted text class data in the application can be stored in the database, especially the data such as chat record, timeline and so on which have conditional query and sorting requirements.

3) CoreData, for planning objects in your app

The CoreData scenario is that the entire application uses CoreData planning to model the data in-app through CoreData, based entirely on the CoreData architecture application.

SQLite uses:

Working with the SQLite database in iOS can be divided into the following steps (note that you first import the LIBSQLITE3 framework into your project):

    1. Open the database, open the database with Sqlite3_open () to specify a database file to save the path, if the file exists directly open, otherwise created and opened. Opening the database will give you an object of type sqlite3 , which you need to use to do other things later.
    2. Executes the SQL statement, and the execution SQL statement also includes statements with return values and no return value statements.
    3. Statements that have no return value (such as additions, deletions, modifications, etc.) are executed directly through the sqlite3_exec () function;
    4. For statements that have a return value, the SQL statement is evaluated first through SQLITE3_PREPARE_V2 () , and then each row of data in the query result is fetched by Sqlite3_step () , For each row of data, the corresponding column data can be obtained through the corresponding sqlite3_column_ type () method, which loops through the loop until the traversal is complete. Of course, the last thing you need to do is release the handle.

iOS data persistence

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.