I have a method that receives a NSArray
of Class
objects and I need to check if they all are Class
type generated with the code bellow:
NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:[NSObject class]];
[arr addObject:[NSValue class]];
[arr addObject:[NSNumber class]];
[arr addObject:[NSPredicate class]];
[arr addObject:@"not a class object"];
The problem is that Class
is not an objective-c class, it is a struc, so I can not use just
for (int i; i<[arr count]; i++) {
Class obj = [arr objectAtIndex:i];
if([obj isKindOfClass: [Class class]]) {
//do sth
}
}
So, I need to I check if the obj
variable is a Class
type, I suppose it will be in C
directly, but how can I do that?
It will be a plus if the answer also provide a way to check if the item in the array is a NSObject
, as the items in the example code, the NSPredicate
would also be true
for the NSObject
check
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…