March 11, 2010

Auto-generating CoreData Classes

Screenshot2010-03-11at6.42.57PM.eAfsUHuqsZyt.jpg
If you have a xcdatamodel file, open it, and using the menu: File > New File > Cocoa Class, you will see an extra item: Managed Object Class. This will autogenerate the required header and implementation files for your CoreData entities so you can use the convenience accessors instead of [setValue:forKey:]. Doing this will also update your data model so your entities won’t have NSManagedObject as their class. Instead their class is the corresponding generated class.

The thing is, you won’t see “Managed Object Class” item unless you have opened the xcdatamodel file and it is the front most window.

Naturally I discovered this by accident just as I was about to hand write the last CoreData model class.

Cheers,
Steve