One of my methods needs to return nil
if no value exists in an dictionary for a specific key or if the value is not of class NSArray
.
This could be done like this:
if (![dict objectForKey:@"key"]) return nil;
id tmp = [dict objectForKey:@"key"];
return [tmp isKindOfClass:[NSArray class]] ? tmp : nil;
I was wondering whether it is well defined to write this mess as:
if (![[dict objectForKey:@"key"] isKindOfClass:[NSArray class]]) return nil;
return [dict objectForKey:@"key"];
What happens here if [dict objectForKey:@"key"]
returns nil
?