子类化NSManagedObject

3 iphone core-data

我为我的Story模型创建了NSManagedObject的子类.我创建了几个新故事:

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

...

[stories addObject:newStory];
Run Code Online (Sandbox Code Playgroud)

然后是:

Story *story = [stories objectAtIndex:[indexPath indexAtPosition:[indexPath length] - 1]];
Run Code Online (Sandbox Code Playgroud)

然而,[story class]由于某种原因,事实证明它实际上是NSManagedObject,而不是Story,当我尝试调用我在Story上定义的方法时,它说unrecognized selector.我究竟做错了什么?

Jam*_*ton 5

确保指定要用于的类NSManagedObject.您可以在Xcode的数据模型编辑器中执行此操作."类"字段位于实体检查器中"名称"字段的正下方.