Testing equality to NSNull Testing equality to NSNull objective-c objective-c

Testing equality to NSNull


Simply check for:

svcUser == [NSNull null]

This is the approach that Apple mentions in their docs.


NSNull is a class. And like with all classes, you must use isEqual:, not == to see if two objects represent the same value.

if (svcUser && ![svcUser isEqual:[NSNull null]]) {    return [svcUser objectForKey:@"access_level"];}


Using @JE42's approach gives me a warning as of Xcode 5.1. Instead cast it:

(id)svcUser == [NSNull null]