#import <Foundation/Foundation.h> #import "Person.h" #import "Student.h" int main(int argc, const char * argv[]) { @autoreleasepool { //创建Person对象 Person *p = [[Person alloc] init]; // Student *stu = [[Student alloc] init]; // p.stu = stu; // p.name = @"张三"; // p.age = 17; // p.gender = @"男"; //setValue:forKey:此方法 value 后跟的参数需要是对象,key后面的参数,是字符串,给对应得属性进行赋值是,参数字符串要与属性名相同 [p setValue:@"张三" forKey:@"name"]; [p setValue:@"男" forKey:@"gender"]; [p setValue:@"24" forKey:@"age"]; [p setValuesForKeysWithDictionary:@{@"name":@"张四",@"gender":@"女",@"age":@16,@"wight":@44}]; [p setValue:@"张狗" forKeyPath:@"stu.name"]; //[stu sayHi]; NSLog(@"%@",p.stu.name); [p sayHi];