user113397
user113397

Reputation:

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?

Upvotes: 3

Views: 1889

Answers (1)

James Huddleston
James Huddleston

Reputation: 8448

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.

Upvotes: 5

Related Questions