How to allow NSMutableDictionary to accept 'nil' values?

后端 未结 3 2088
遇见更好的自我
遇见更好的自我 2021-02-12 16:01

I have this statement:

 [custData setObject: [rs stringForColumnIndex:2]  forKey: @\"email\"];

where [rs stringForColumnIndex:2] o

3条回答
  •  攒了一身酷
    2021-02-12 16:52

    There is a non-nil object called NSNull that is built specifically to represent nils in situations where "plain" nil is not acceptable. If you replace your nils with [NSNull null] object, NSDictionary will take them. You would need to check for NSNull on the way out, though.

    Note that this is important only when you must differentiate between a value not being set and a value being set to nil. If your code is such that it can interpret a missing value as nil, you do not need to use NSNull at all.

提交回复
热议问题