Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclassing NSManagedObject

I made a subclass of NSManagedObject for my Story model. I create several new stories like so:

Story *newStory = [NSEntityDescription insertNewObjectForEntityForName:@"Story" inManagedObjectContext:context];

...

[stories addObject:newStory];

And then later on:

Story *story = [stories objectAtIndex:[indexPath indexAtPosition:[indexPath length] - 1]];

However, it turns out that [story class] is actually NSManagedObject, not Story, for some reason, and when I try to call a method that I defined on Story, it says unrecognized selector. What am I doing wrong?


1 Answers

Make sure you specify the class that you want to use for your NSManagedObject. You do this in Xcode's data model editor. The "Class" field is right below the "Name" field in the Entity inspector.

like image 125
James Huddleston Avatar answered Mar 07 '26 21:03

James Huddleston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!