Search code examples
objective-ciphonecocoa-touchios4null

What is wrong with this NULL check for a ViewController?


myCustomController *controller = [myMutableArray objectAtIndex:page];

NSLog(@"%@",controller); // <- THIS RETURNS NULL IN CONSOLE

if ((NSNull *)controller == [NSNull null]) {
 // Why is the above check not working if controller in console says it's null?
 // It's not jumping into this loop. Has something changed in iOS4.0 SDK?
}

what is wrong with this null check for a viewController, it does not seem to be working.


Solution

  • NSLog should return (null) (which probably is description for nil), not NULL in console. Your check should look like this:

    if (!controller) {
      // do some stuff here
    }