0

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 insertNewObjectForEntityForName:@"Credit" inManagedObjectContext:context];

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

2 Answers 2

2

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".

1

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

2
  • damn - the editor... I had mapped it to "Credits" by mistake. Thanks!
    – LK.
    Jun 14, 2011 at 21:00
  • Yeah, you don't get any sort of warning if you miss it. One way to ensure it's always right (aside from tests, obviously) is to generate the classes from the model in the model editor.
    – Thom
    Jun 14, 2011 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.