views:

84

answers:

2

I'm trying to recognize the result of a generic query to a managed object as an NSSet. Currently the class returned is a member of _NSFaultingMutableSet, which is clearly related, but fails the isMemberOf:[NSSet class] and isKindOf:[NSSet class] calls.

Given that Cocoa doesn't do a direct implementation of NSSet, it's not surprising that I've got some air in the pipes, but I'm wondering if I'm messing something obvious up or this requires a higher grade of kung-fu than I possess.

Code follows:

SEL selector = NSSelectorFromString(someString);
 if(![self respondsToSelector:selector]){
  NSLog(@"Error processing item");
                return;
 }
 id items = [self performSelector:selector];
 Class itemsClass = [items class];
 if ( [itemsClass isKindOfClass:[NSSet class]]) {
      // do something
        }
A: 

Ha! My problem was solved, as usual, by RTFM. It turns out that if you are NOT supposed to call isKindOf: on a class itself, as I was, but rather on the particular instance. Tsk tsk.

Will
A: 

Alternatively, NSObject does have an isSubclassOfClass: class method (introduced in Mac OS X 10.2). You could do:

if ([itemsClass isSubclassOfClass:[NSSet class]])
{
    // do something
}

Although, it probably is easier to simply test the instance itself.

dreamlax