iOS: Why can't I set nil to NSDictionary value?

后端 未结 5 1429
清酒与你
清酒与你 2020-12-29 01:15

This might be very basic question but I was wondering why can\'t I assign nil as NSDictionary value? I have following statement many places in my code. If [q objectFor

5条回答
  •  长发绾君心
    2020-12-29 02:13

    When using this method:

    func setObject(_ anObject: Any, forKey aKey: NSCopying)
    

    Parameters (according to Apple doc's):

    anObject:

    Raises an invalidArgumentException if anObject is nil. If you need to represent a nil value in the dictionary, use NSNull .

    aKey

    Raises an invalidArgumentException if aKey is nil.

提交回复
热议问题