#import <Foundation/Foundation.h>#import"Person.h"#import"Student.h"intMainintargcConst Char*argv[]) {@autoreleasepool {//Create Person ObjectPerson *p =[[Person alloc] init]; //Student *stu = [[Student alloc] init]; //p.stu = stu;//p.name = @ "Zhang San";//p.age = +;//P.gender = @ "male"; //Setvalue:forkey: This method value followed by the argument needs to be an object, the argument after the key, is a string, the corresponding property is assigned to, the parameter string to be the same as the property name[P SetValue:@"Zhang San"Forkey:@"name"]; [P SetValue:@"male"Forkey:@"Gender"]; [P SetValue:@" -"Forkey:@" Age"]; [P setvaluesforkeyswithdictionary:@{@"name":@"Zhang Si",@"Gender":@"female",@" Age":@ -,@"Wight":@ -}]; [P SetValue:@"Zhang Dog"Forkeypath:@"Stu.name"]; //[Stu Sayhi];NSLog (@"%@", P.stu.name); [P sayhi];
Simple KVC in iOS