不疯不成魔

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#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];

 

posted on 2015-09-07 20:07  不疯不成魔  阅读(141)  评论(0编辑  收藏  举报