如何判断NSDictionary是否包含某个键

方法一:

if ([[dictionary allKeys] containsObject:key) {     // contains key } 

方法二:

if ([dictionary objectForKey:key]) { //objectForKey will return nil if a key doesn't exists.      // contains key }

你可能感兴趣的:(Dictionary)