subclassed NSManagedObject does not call description when NSLog'd
I have a data model which has two entities in a relationship of one to many.
Each entity has a class that is subclassed from NSManagedObject.
I get the relation set for the one entity and walk it casting each set member to the specific subclass as I enumerate the collection.
When I 开发者_运维问答do
NSLog(@"My Entity: %@", myEntityInstance);
It logs but does not call my subclass's method for:
- (NSString*) description
It does call if I send:
NSLog(@"My Entity: %@", [myEntityInstance description]);
Any ideas what is being called and why description has to be manually called?
Thanks!
If a class instance responds to descriptionWithLocale:
, then NSLog
will use that instead. Although descriptionWithLocale:
does not appear in NSManagedObject
's list of instance methods, it could possibly still be implemented.
Try overriding descriptionWithLocale:
and see if that makes a difference.
- (NSString *) descriptionWithLocale:(id) locale
{
return @"my description";
}
I've never seen that. I don't think it's a NSManagedObject behavior. You might log the class before making the call to make sure your instance is of the class you think it is.
Might be two years or so late to the game, but for the benefit of others, I had this problem tonight. The cause was that, while I had made NSManagedObject subclasses for my entities, one of the entities in the CoreData Modler had it's "Class" set back to NSManagedObject instead of the custom subclass.
It didn't matter what I put into -description in my subclass files, because the objects were coming out of the Context as NSManagedObjects instead of my custom subclass.
Putting the subclass name back in the Entity Inspector in the Xcode Coredata Model Editor fixed it.
精彩评论