Swift Language IOS8 Development battle Note Core Data1

Source: Internet
Author: User
Tags sqlite database

Core data literally means the kernel, but it's not a database, it's a framework, just like the foundation we used to use, it's very handy to use core data when we do it. The following is a schematic diagram of the core data framework:


We are going to create a new project to add core data to the learning.

Create a new project, you can see the option to have a core data specific when adding new file to the project




We select the data Model, create, use the default name, and now see a Model.xcdatamodeld in the project, click the Down button to add an entity:


Named info, which adds properties to the attributes, looks like a table's properties:


This option is useful if the relationships is an association and there is an association between entity entities. The entity is created, the entity has attributes, and the work of Core data initialization is done.

Persistent time will generally choose Sqlite,core data only in the foreground to do encapsulation, do not care about the background with what implementation.

Analysis of the above CoreData structure diagram, to use CoreData general practice is:

1. To create a SQLite database, you need to have the path and DB Name.

The objects that 2.Core data uses are Nsmangeobject, Nsmangeobjectcontext, and Nsentitydescription. Nsmangeobject is a data object, Nsmangeobjectcontext is the context of the management object, used to cache our query operations, Nsentitydescription is an entity description, used to describe the object we are looking for.

Nsmangeobjectcontext relies on Nspersistentstorecoordinator (persistent storage coordinator) and Nsentitydescription, which is equivalent to the memory space for the user to operate, Our operations are written to the database only if we call the final save method when we are done.

Nspersistentstorecoordinator needs to know the type, path, and file name of Nsmanageobjectmodal and storage to coordinate user and underlying data.

Nsmanageobjectmodal: Equivalent to the underlying, similar to the functionality of a database object, generated by a. momd file. When we created the model above, the generated. Xcdatamodeld file was compiled and generated a. momd file.

In the next word, we will understand the above content by example, open the Appdelegate file, and keep its first method on the line.


Swift Language IOS8 Development battle Note Core Data1

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.