zoukankan      html  css  js  c++  java
  • Chapter 23 Core Data

    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.

  • 相关阅读:
    关于李约瑟难题的思考
    《MDX解决方案(第2版)》实例数据部署过程
    在SQL SERVER 2008种使用表值参数
    解决了一个想了很久的问题
    发现可以在两个数据库中共享只读文件组
    java 包位置
    单元测试java
    Cannot determine build data storage root for project
    Vue——绑定值
    浪潮之巅第八章 — 没落的贵族(摩托罗拉)
  • 原文地址:https://www.cnblogs.com/1oo1/p/4007460.html
Copyright © 2011-2022 走看看