Comparison between CoreData and SQLite

Source: Internet
Author: User

Comparison between CoreData and SQLite

CoreData provides an ORM (object relationships Mapping) solution that directly generates the corresponding model object file and encapsulates some of the underlying operations, simplifying usage, while SQLite uses C to invoke the corresponding API. And do some of the underlying encapsulation operations, and the model object file to write their own, the code will be slightly larger, the other feeling is not too much.

After looking up some information, briefly summarize the following:

First, the concept of CoreData and SQLite is different, the core is the object cycle management, and SQLite is the DBMS.
The following discussion is based on the use of core data to persist and use SQLite as a backend storage condition.

    1. Ease of use. In fact, a mature project must be a data persistence package, so the bottom of the use of core data or sqlite, should not be the business logic developers concerned. Therefore, even people who are accustomed to writing SQL queries should avoid writing SQL statements directly in the business logic.
    2. Storage performance, in the write performance, because all are used in the SQLite format as a disk storage format, so its performance is the same, if you think with core data write slow, it is likely that you use SQLite when you write the content of each piece of data without core data when more, Or when you write in bulk, the save is called every time you write a message.
    3. Query performance, core data is compatible with a variety of backend formats, so when querying, its available statements are less than the direct use of sqlite, so some fetch is not actually performed in SQLite. However, this will not necessarily reduce the efficiency of the query. Because the iphone flash memory speed is still very fast. My experience is that most of the time, when the memory is not very tense, it is often faster to fetch all the data from an entity and then make the filter in memory more quickly than using predicate in fetch. If you think the query is slow, it is likely that the query method has a problem, you can open the debug mode of core data to see how many SQL statements executed, I believe most of them can be overridden by the core data to avoid the call way.
    4. One of the big pain points of core data is that when people work together, the model of managing coredata needs to be careful, especially when merging, his data model is in XML format, and manual resolve is more annoying.
    5. Core data has other advantages that SQL does not have, such as support for undo, and multiple context implementations sketchbook similar functionality. The row cash optimized for ManagedObject.
    6. In addition, core data is multi-threaded, but requires thread confinement implementation, using multithreading can be maximized to prevent blocking the main thread.

What is a nsmanagedobject model in CodeData? What is Nsmanageobjectcontext?

1. Nsmanagedobject is a subclass of NSObject and an important part of CoreData, it is a generic class that implements the basic functions required by the core data model layer, and the user can nsmanagedobject by subclasses, Build your own data model.

2. The Nsmanagedobjectcontext object is responsible for the interaction between the application and the database.

Comparison between CoreData and SQLite

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.