码迷,mamicode.com
首页 > 其他好文 > 详细

Chapter 23 Core Data

时间:2014-10-06 00:12:19      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   sp   art   c   on   r   ad   

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 particular 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 things:” 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

标签:io   ar   for   sp   art   c   on   r   ad   

原文地址:http://www.cnblogs.com/1oo1/p/4007460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!