As others have said, neither NSDictionary nor NSArray can contain nil values. However, they may contain an (singleton) NSNull , and NSDictionary will return nil from objectForKey if the key is not found.
In terms of a “protective” link, especially with decoded JSON, you may need a few checks.
First of all, make sure you really have the expected kind of object (some JSON providers can return an external array for one access and an external dictionary for the next) using isKindOfClass : if ([iThinkItsADict isKindOfClass:(NSDictionary class)]) { ...
Next, if you are accessing an array, make sure that the index you are going to use is within the array (bearing in mind that the array can have null entries): if (arrayIndex < someArray.count) { ...
When a value is returned from the dictionary, it may be nil if the key was not found. Thus, you can test with if (returnedValue != nil) {... (although note that if the value "nil" is used to "send" a method call, the call will succeed without an error, but returns zero / zero. Therefore, it is not necessary to check zero.
A dictionary or array can return NSNull, with which you can check with if (returnedValue != [NSNull null]) {... (Some will object that you should not use == or != To compare objects for equality, but there is only one NSNull in the application.)
source share