开发者

Unexpected class type for object created using 'insertNewObjectForEntityForName'

I have two different objects which I create using insertNewObjectForEntityForName using the same context.

My problem is that for the first object, Event, the object type is correctly defined as Event, while for the second object which should be of type Credit, the object type is instead NSManagedObject (which means I can't called methods defined in the derived class on it).

Object 1: (as expected)

Event *event = (Event*)[NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:context];

(gdb) po event
<Event: 0x62b3f00> (entity: Event; id: 0x62b3fb0 <x-coredata:///Event/tD3B27884-D303-4FDE-9D0F-D7DC009E2EBB18> ; data: {
...
})

Object 2: (expected class to be Credit and not NSManagedObject)

Credit *credit = (Credit*)[NSEntityDescription insertNewObjectForEntityFo开发者_开发技巧rName:@"Credit" inManagedObjectContext:context];

(gdb) po credit
<NSManagedObject: 0x629fd50> (entity: Credit; id: 0x628caf0 <x-coredata:///Credit/tD3B27884-D303-4FDE-9D0F-D7DC009E2EBB36> ; data: {
...
})


You don't have a custom class name assigned for the entity in the data model so the context just returns a generic managed object instance. Right now it just says, "NSManagedObject" instead of "Credit".


Presumably you've double-checked that the entity is indeed mapped to the Credit class in the model editor?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜