1: Differences and relations between setobject: forkey: and setValue: forkey:
1. Setobject: forkey: unique to nsmutabledictionary;
SetValue: forkey: is the main method of KVC;
2. Setobject: forkey:Object cannot be nil, otherwise an error will be reported
;As long as the parameter of key is an object, it is not limited to nsstring
;
The value in setValue: forkey: can be nil, and the removeobject: forkey: method will be called automatically at this time;The parameter of key can only be nsstring type
;
3. Nil is different from null, [nsnull null] indicates that it is an empty object, not nil;
4. SetValue: forkey: it is created in the nsobject object, that is, all objects have this method, which can be used in any class; (when the method caller is an object)
2: Objectforkey: and valueforkey:
There are two methods for nsdictionary value, objectforkey: and valueforkey:
(it is recommended to use objectforkey:)
1.If the key does not start with @ match, they are the same
;
2.If key starts with @
For example: @ “@ hhisiskey”, valueforkey: will remove @, and then execute [super valueforkey] with the rest;
3. Example: person * person = [person alloc] init];
person.name = @“Chen”;
Pass: [person valueforkey: @ “name”]; Take out: Chen. This is KVC’s method.
4. Valueforkey: the value is to find a property accessor with the same name as the specified key. If it is not found, execute valueforundefined key:, while valueforundefined key: by default, throw a crash exception;