Analysis of CoreData in iOS

Source: Internet
Author: User

CoreData Introduction:

    • What is CoreData?

      • Core data is a framework that appears after IOS5, which provides object-relational mapping (ORM) functionality that enables you to convert OC objects into data, store them in SQLite database files, and restore data saved in a database to OC objects. During this data operation, we do not need to write any SQL statements

      • CoreData cannot execute SQL statements instead, manipulating objects. And the common three-party library FMDB SQLite can be directly SQL statements

    • What is the difference between a coredata and a database?

      • CoreData is an apple-native framework that has the ability to store data like a database, but it is not a database

        • Core data is a powerful framework in the iOS SDK that allows programmers to store and manage data in an object-oriented manner. Using the core data framework, programmers can easily and efficiently manage data through an object-oriented interface, so CoreData is not a database, not a database view.
      • Core Data 不是应用程序的数据库,也不是将数据持久化保存到数据库的API。Core Data 是一个 用于管理对象图的框架。Core Data 可以把对象图写入磁盘从而持久化保存

    • What are the characteristics of coredata?

      • (1) CoreData provides a model-level technology that allows data persistence directly on OC objects

        • Core Data is the technology of a model layer. To help build a model layer that represents the state of the program, core data is also a persistent technology that can persist the state of the model object to disk, but its most important feature is that core data is not only a framework for loading and saving the database, but also working well with the in-memory data.
      • (2) CoreData does not need to write any SQL statements during the storage operation of the data

      • (3) Core Data uses content that includes entity and entity relationships, and finds requests that meet certain conditional entities

      • (4) Developers can find and manage this data on a pure object layer without worrying about the implementation details of storage and lookups

      • (5) Core Data framework first appeared in Mac OS X 10.4 Tiger and iOS 3.0 system, through thousands of applications and the repeated verification of millions of users, Core data is really a set of very mature framework

      • (6) CoreData leverages the Objective-c language and runtime to subtly integrate the core Foundation framework. is an easy-to-use framework that not only gracefully manages object graphs, but also provides exceptional performance in memory management

coredata principle:

    • The first glimpse of the formidable complex architectural relationship of core Data is that many people have a feeling

    • However, once you understand the composition and the relationship between the components in the architecture diagram, you can realize the simplicity and intuition of the core Data API.

    • Core Data stack(技术堆栈):如果能够理解Core Data stack 中的各个成员所扮演的角色,那么再 使用Core Data 就不会感觉到困难了

1.1-What is CoreData Stack?
    • Core data stack is at the heart of core data and consists of a set of core data kernel objects

      • Nsmanagedobjectcontext Object Management Context: Collection of objects responsible for managing the model

      • Nsmanagedobjectmodel Managed Object Model: Responsible for managing the object model

      • Nspersistentstorecoordinator Storage Scheduler: Responsible for saving data to disk

1. How do the objects in the 2-coredata stack coordinate their work?

    • The composition can be divided into two parts

      • Object Graph management: mainly refers to the object management context (Nsmanagedobjectcontext) by implementing object management on the object Model (Nsmanagedobjectmodel).

      • Data persistence: Mainly refers to the memory (Nspersistentstore) to operate the SQLite database, the data stored in the disk (this part of the system to help us do not need our tube).

        • In the middle of the two parts, the middle of the stack, is the persistent storage Coordinator (persistent store coordinator, PSC). It binds the object Graph Management Section and the persistence section together. When part of the two parts needs to interact with another part, it will be adjusted by the PSC.
    • One of the points of attention:
    • A project can have multiple management model context, a storage scheduler can dispatch multiple storage, but in general development, we only need a contect and a memory is enough

Analysis of CoreData in iOS

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.