KVC is a Key , value , Coding the abbreviation, that is, the key value encoding. In IOS , property information for an object can be accessed indirectly through the name of the class's property (key).
build a project to create a Zzperson class, which has two properties, name and the Address .
ZzPerson.h: #import <Foundation/Foundation.h> @interface zzperson:nsobject{ nsstring * name,address; } @endViewController. h: The Zzperson class header file is introduced in the ViewController.h file, Viewcontroller has a property of the Zzperson type Sam. #import <UIKit/UIKit.h> #import "ZzPerson.h" @interface viewcontroller:uiviewcontroller@property (Nonatomic, Retain) Zzperson * SAM; @endViewController. M: #import "ViewController.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload { [super viewdidload]; Create Zzperson object Sam _sam=[[zzperson Alloc]init]; Set object Sam information via Key,value [_sam setvalue:@ "Tangled Lun" forkey:@ "name"]; [_sam setvalue:@ "" forkey:@ "Address"]; Information about the SAM object is accessed through the person's properties. NSLog (@ "%@", [_sam valueforkey:@ "name"]); NSLog (@ "%@", [_sam valueforkey:@ "Address"]);
A Class ( Zzperson ) of the object ( Sam ) by SetValue : Forkey statement to set the information for an object property, where Key is the class ( Zzperson ) is also the property of the object ( Sam ) of the Zodiac, where the Key respectively is name and the Address , through Key to set their information. The Valueforkey is then called by the object : The statement can access The property information corresponding to the key.
kvc-Key value encoding