Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert existing object model to Core Data managed object model

I am developing an iOS app and have several object models. Now I want to convert them to core data managed objects, so creating the entities and attributes from the object instead of the standard opposite way of generating the objects from the model. What is the best way to accomplish this?

I tried extending from NSManagedObject instead of NSObject, then manually creating the entities and attributes and setting up the Class name for the entity but that didn't work :-(

Thanks

like image 340
momo Avatar asked Jan 30 '13 07:01

momo


1 Answers

I recently did this for a big project with a very large and complex data model. Here is a workflow that I found to be very feasible.

First, I create a new data model in Xcode and populate it by hand. This is a very good exercise as it forces you to review your model and perhaps take advantage of simplification opportunities.

Then, generate your class files with Xcode from the model. If you have any special code that should be included in the objects, add them as categories in separate files (e.g. Event.h & Event.m generated by Xcode, Event+Additions.h & Event+Additions.m with your code).

like image 175
Mundi Avatar answered Nov 15 '22 06:11

Mundi