Alex Rivera | Logout

How to check if an NSDictionary or NSMutableDictionary contains a key?

Asked 2010-05-06T21:27:52.217
473

I need to check if an dict has a key or not. How?

Edit
Report

1 Answer

3

Because nil cannot be stored in Foundation data structures NSNull is sometimes to represent a nil. Because NSNull is a singleton object you can check to see if NSNull is the value stored in dictionary by using direct pointer comparison:

if ((NSNull *)[user objectForKey:@"myKey"] == [NSNull null]) { }
answered 2011-07-07T22:07:15.367

Your Answer