The simplest way is:
[dictionary objectForKey:@"key"] != nil
as dictionaries return nil
for non-existant keys (and you cannot therefore store a nil in a dictionary, for that you use NSNull
).
Edit: Answer to comment on Bradley's answer
You further ask:
Is there a way to verify if this: [[[contactDetailsDictionary objectForKey:@"professional"] objectForKey:@"CurrentJob"] objectForKey:@"Role"] exists? Not a single key, because is a really giant dictionary, so it could exist in another category.
In Objective-C you can send a message to nil
, it is not an error and returns nil
, so expanding the simple method above you just write:
[[[contactDetailsDictionary objectForKey:@"professional"]
objectForKey:@"CurrentJob"]
objectForKey:@"Role"] != nil
as if any part of the key-sequence doesn't exist the LHS returns nil