How do I verify if a key exists on a NSDictionary?
I know how to verify if it has some content, but I want to very if it is there, because it’s dynamic and I have to prevent it. Like in some cases it could happen to have a key with the “name” and is value, but in another cases it could happen that this pair of value don’t exists.
The simplest way is:
as dictionaries return
nilfor non-existant keys (and you cannot therefore store a nil in a dictionary, for that you useNSNull).Edit: Answer to comment on Bradley’s answer
You further ask:
In Objective-C you can send a message to
nil, it is not an error and returnsnil, so expanding the simple method above you just write:as if any part of the key-sequence doesn’t exist the LHS returns
nil