I have a method that receives many different kinds of objects and decides what to do with them:
-(void)performAction:(NSObject *)myAction withItem:(Item *)my
Two possibilities worth considering:
NSArray
is a class cluster. I don't know the exact behaviour of -isMemberOfClass:
and -isKindOfClass:
on clusters. you can check this question for more precisions: Is it safe to use isKindOfClass: against an NSString instance to determine type?
Have you tried -isKindOfClass:
instead of -isMemberOfClass:
?
NSСFArray is subclass of NSMutable Array
You can use isKindOfClass to check it
if ([myAction isMemberOfClass:[Look class]]) {
currentActionArray = [self createLookArray:(Look *)myAction item:myItem];
} else if ([myAction isMemberOfClass:[Use class]]) {
currentActionArray = [self createUseArray:(Use *)myAction item:myItem];
} else if ([myAction isMemberOfClass:[Exit class]]) {
currentActionArray = [self createExitArray:(Exit *)myAction item:myItem];
} else if ([myAction isKindOfClass:[NSArray class]] ) {
NSLog(@"--- CUSTOM ACTION --- %@", myAction);
currentActionArray = (NSArray *)myAction;
}
You can try using isKindOfClass:
instead of isMemberOfClass:
.
The first one will return YES for objects that are either instances of the class you send, or subclasses of it, as it may be the case for NSCFArray
.