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

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

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

16条回答
  •  有刺的猬
    2020-11-28 01:31

    When using JSON dictionaries:

    #define isNull(value) value == nil || [value isKindOfClass:[NSNull class]]
    
    if( isNull( dict[@"my_key"] ) )
    {
        // do stuff
    }
    

提交回复
热议问题