KVC use

KVC is used as follows:

(1) using the object attribute assignment to call two methods as follows

- (void)setValue:(nullable id)value forKey:(NSString *)key;

- (void)setValue:(nullable id)value forKeyPath:(NSString *)keyPath;

 

Wherein, setValue: forKeyPath: this method, the path can be assigned attributes.

That means, RiJiModel has a "MYCRiJiDiaryModel" diary type objects, and a diary class has attributes of the title,

 

 

 

So, it can be assigned to objects rijiModel the title diary:

[rijiModel setValue:@"this is a title name"   forKeyPath:@"diary.title"];

This forKeyPath diary will first find the object, the object is to find title diary of assignment;

 

(2) modify private member variables

oc system has many private member variables, with the point assignment method can not change the value of this private member variables.

But using setValue: forKeyPath: can be modified.

 

(3) Value

Conventional do not speak, to say the more interesting:

 

 

Using arrays, there are a few more interesting:

 

 

 

 

First: Fetch the number array;

The second: taking an object array, the oldest value;

Third: taking an array of objects, the youngest value;

Fourth: Take an array of objects, the average age.

Guess you like

Origin www.cnblogs.com/lyz0925/p/11440463.html