Chapter 23 core data

Source: Internet
Author: User
Tags sqlite database

Chapter 23 core data

 

1. core data is only able to store certain data types in its store, And uiimage is not one of these types. instead, you declared the uiimage as transformable. with a transformable attribute, core data will convert the object into nsdata when saving, and convert the nsdata back into the original object when loading it from the file system. in order for core data to do this, you have to supply it with an nsvaluetransformer subclass that handles these conversions.

 

2. an nsmanagedobject is little more than a data container. if you need your model objects to do something in addition to holding data, you must subclass nsmanagedobject. then, in your model file, you specify that this entity is represented by instances of your subclass, not the standard nsmanagedobject.

 

3. the portal through which you talk to the database is the nsmanagedobjectcontext. the nsmanagedobjectcontext uses an nspersistentstorecoordinator. you ask the persistent store coordinator to open a SQLite database at a particle filename. the persistent store coordinator uses the model file in the form of an instance of nsmanagedobjectmodel. the persistent store Coordinator needs to know two thi NGS: "what are all of my entities and their attributes and relationships ?" And "Where am I saving and loading data from ?" To answer these questions, you need to create an instance of nsmanagedobjectmodel to hold the entity information and initialize the persistent store Coordinator with this object. then you will create the instance of nsmanagedobjectcontext and specify that is use this persistent store coordinator to save and load objects.

 

4. to get objects back from the nsmanagedobjectcontext, you must prepare and execute an nsfetchrequest. after a fetch request is executed, you will get an array of all the objects that match the parameters of that request.

Chapter 23 core data

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.