码迷,mamicode.com
首页 > 移动开发 > 详细

iOS中简单的KVC

时间:2015-09-07 20:59:24      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

#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];

 

iOS中简单的KVC

标签:

原文地址:http://www.cnblogs.com/wohaoxue/p/4789833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!