I need to check the type of each element in an array…
for(id obj in items) {
if([obj isKindOfClass:[NSString class]]) {
//handle string case
} else if([obj isKindOfClass:[NSInteger class]]) { //THIS LINE GIVES ERROR
//handle int case
}
}
Of course NSInteger is just an alias for int, so how can I check for this at runtime?
You can’t actually store
NSIntegerin anNSArray, since it isn’t an object. If you are storing numbers in your array, they are most likely instances ofNSNumber, so you would check for:iPhone Developer Tips gives a good summary of the difference between
NSIntegerandNSNumber.