Reprinted from Http://www.tuicool.com/articles/2aYfy2
Key-value coding, which is a mechanism that uses string identifiers to indirectly access object properties, rather than calling getter and setter methods directly. Often we use Valueforkey instead of getter methods, Setvalue:forkey to replace setter methods.
First look at the difference between KVC and Setter,getter method assignment
Persion *person = [[Person alloc] init]; // do not use KVC @" Hufeng " ; // using the KVC notation [Person SetValue:@ "hufeng" forkey:@ "name" ];
Here we write a complicated point: we have a person this person has a cell phone this phone class has a battery class we want to get this battery class.
// Using Attributes Persion *person = *phone =*battery = phone.battery;
Using KVC
@" Phone.battery " ];
Note-The value inside the Valueforkeypath is case-sensitive, and you can't do it if you write the phone.battery.
The most common use of KVC is in serializing and deserializing session objects. We often need to deserialize the JSON string into the object we want. Below is an example of serializing a dictionary into an object using Nskeyedarchiver.
-(ID) initwithdictionary: (nsdictionary *) dictionary { = [self init]; if (self) { [self setvaluesforkeyswithdictionary:dictionary]; } return Self ;}
About KVC Key-value encoding