The differences between dictionaries SetValue and SetObject

Source: Internet
Author: User

Note: Setobject:forkey: The object in key is an ID type, not a nsstring, but we often use nsstring.

1, Setobject:forkey: In value is not able to nil, or will error.

Setvalue:forkey: Value can be nil, but when value is nil, the Removeobject:forkey method is called automatically

2, Setvalue:forkey: The parameter in key can only be nsstring type, and Setobject:forkey: can be any type

Note: Setobject:forkey: objects cannot hold nil to differentiate from this situation:

nsmutabledictionary* dic [email protected] {@ "K1": @ " good person", @ "K2": @ " bad guy" @ "K3": @ " man" @ "K4": @ " woman"};

1, [dic setobject:[nsnullnull] forkey:@ "K5"];

[NSNull null] represents an empty object, not nil, note this

The differences between dictionaries SetValue and SetObject

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.