Object-C 获取对象的属性和值

来源:互联网 发布:类似whatsapp的软件 编辑:程序博客网 时间:2024/05/17 06:01
@autoreleasepool {                TestObj *obj = [[TestObj alloc]init];        obj.age = @"22";        obj.name = @"lisi";        obj.gender = @"male";                unsigned int count;        objc_property_t *properties = class_copyPropertyList([obj class], &count);        for(int i=0;i<count;i++){            objc_property_t property = properties[i];            NSString *key = [[NSString alloc]initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];            //kvc读值            NSString *value = [obj valueForKey:key];            NSLog(@"%@->%@",key,value);        }    }

1 0
原创粉丝点击