简体   繁体   中英

iOS add entity to core data from class

I've created an app, and want to add core data functionality.

I have two classes - project and photo , is there a way to easily add them to my core data model . I know it is possible to do the reverse and create a class from an Entity in the model.

I'm using Xcode 4.3.

There is no built-in tool that looks at your class and updates the core data model in Xcode.

However, it isn't particularly difficult to do. Assuming these classes are principally used for data storage:

  • Remove everything from your class that relates to data storage, leaving only the property declaration.
  • Add a @dynamic statement for each property (instead of a @synthesize - this must go).
  • Make your object a subclass of NSManagedObject instead of NSObject.
  • Add the entities into your data model with the appropriate attributes, and set the class to your modified class.

If you're talking about updating an existing app that is using plists to store, and you want to migrate existing data into your core data store, that is a separate routine you would have to include in your app to run on the first launch of the new version.

Storing an image in Core Data can be as efficient as storing a URL or a file URL. The important step is in Xcode: Check the image data attribute, "Store in external record file".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM