Unexpected class type for object created using 'insertNewObjectForEntityForName'
I have two different objects which I create using insertNewObjectForEntityForName
using the same context.
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?
精彩评论