How to check if an NSDictionary or NSMutableDictionary contains a key?

前端 未结 16 2886
北海茫月
北海茫月 2020-11-28 00:52

I need to check if an dict has a key or not. How?

16条回答
  •  孤街浪徒
    2020-11-28 01:35

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

    or

    if ([dictionary objectForKey:key]) {
        // contains object
    }
    

提交回复
热议问题