I have an NSArray (RSIatAddr), and I want to check whether the object at the given index = 0 (or some other arbitrary constant) but the following code gives me no warnings / error ; but is throwing an exception
if ([[RSIatAddr objectAtIndex:j] isEqualToNumber:nil]) {
[sumRSI addObject:[NSNumber numberWithInt:[[RSIatAddr objectAtIndex:j]intValue]*
[[sumRSI objectAtIndex:j] intValue]]]; }
The error I’m getting:
2012-10-02 00:42:00.266 NetSearch+DetectLocation[3741:707]
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFNumber compare:]: nil argument'
Without seeing the code that actually fills your array, its likely the array is holding a different type than you are expecting. Try setting a breakpoint right before that line of code, and typing “po [[RSIatAddr objectAtIndex:j] class]” and see what is actually there, then you can also try your isEqualToNumber in the debug window to see if that succeeds.
I just implemented this in the AppDelegate of a new iOS App and it works: