NSManagedObject

I’ve been discovering the intricacies of managing NSManagedObjects. These are the objects that you as a developer have to use when developing with Core Data. Because of the level of control over the lifecycle of the objects that Core Data takes, the normal -(id)init; and -(void)dealloc; methods should not be overridden in a subclass of NSManagedObject.

Instead, you need to use the NSEntityDescription class method

+ (id)insertNewObjectForEntityForName:(NSString *)entityName

inManagedObjectContext:(NSManagedObjectContext *)context;

This method returns a NSManagedObject of the type noted by the entityName parameter.

While dealing with all this stuff. I realized I don’t understand all the in’s and out’s of how the model creates objects. I had the model backwards, as the one Channel contains many Items, but the model reversed that, so I had to pull some hackery to get what I want.

One little key, if you modify the model, you’ll have to delete the files in ~/Library/Application Support/iPhone Simulator/<version>/Applications/. I deleted everything in there and it was happy again.

At this point, I’m getting data into the model, and that’s good enough for now. I still need to deal with new vs. existing entries, but that’s for another time. It’s now time to move on to the RootViewController and start displaying the data available.

This entry was posted in iOS, Objective-C, Sound Church, XCode and tagged , , . Bookmark the permalink.

Comments are closed.