1.获取属性名
objc_property_t name_property = class_getProperty(NSPerson.class, "name");
const char * property_name = property_getName(name_property);
NSLog(@"name_property:%s",property_name);
2.获取属性信息
const char * property_attributes = property_getAttributes(name_property);
NSLog(@"property_attributes:%s",property_attributes);
3.拷贝属性信息
unsigned int attributes_count;
objc_property_attribute_t *attributes_list = property_copyAttributeList(name_property, &attributes_count);
for (int i = 0; i < attributes_count; i++) {
objc_property_attribute_t attribute = *(attributes_list + i);
NSLog(@"name_%i:%s,value_%i:%s",i,attribute.name,i,attribute.value);
}
free(attributes_list);
4.拷贝指定属性信息的值
char * property_value = property_copyAttributeValue(name_property, "V");
NSLog(@"property_value:%s",property_value);
free(property_value);