Skip navigation.
 
mlRe: Using isMemberOfClass with a tree of subclass of NSManagedObject
FROM : Yoann GINI
DATE : Sat Jun 28 20:07:25 2008

This doesn't work with isKindOfEntity, used like that :

   NSEntityDescription*        rootDescription        = [[NSEntityDescription 
entityForName:@"root" inManagedObjectContext:[self 
managedObjectContext]] retain];
...
   [rootDescription isKindOfEntity:[modEntry entity]]

It's always return NO...


Le 28 juin 08 à 19:32, mmalc crawford a écrit :

> On Jun 28, 2008, at 10:15 AM, Owen Yamauchi wrote:

>>
>> On Jun 28, 2008, at 9:58 AM, Yoann GINI wrote:

>>>     I've a CoreData base with some kind of object what are a subclass 
>>> of an abstract class called "root" (root is a subclass of 
>>> NSManagedObject). In a part of my code I need to catch all 
>>> operation on object what are a child of root. For do that I use 
>>> the notification 
>>> NSManagedObjectContextObjectsDidChangeNotification and I would use 
>>> "isMemberOfClass" method for test each objet. I don't know why but 
>>> this method always return "NO" even of an object what are a chlid 
>>> of root...
>>>

>> Use -isKindOfClass: instead. -isMemberOfClass: only tells you if an
>> object is an instance of that specific class. -isKindOfClass: 
>> includes
>> all superclasses as well.
>>

> isKindOfClass: includes all *subclasses* as well.
>
> You should almost certainly, though, not be using class-based tests 
> -- you should instead test the entity of the managed object (if you 
> need to test for subentities, use isKindOfEntity).
>
> mmalc
>