判断NSDictionary是否包含某个键key的方法
在某些情况下,我们需要通过判断字典里某个键key的存在与否,去执行一些特定的操作,一般常用的方法有两种:
方法一:
if ([dictionary allKeys] containsObject: key]){
// cotains key
operation;
}
方法二:
if ([dictionary objectForKey: key]
){ // objectForKey will return nil if a key doesn't exists.
// cotains key
operation;
}