runtime获取属性、方法、变量、协议
unsigned int count;
//获取属性列表//利用这个属性可以实现给Model类赋值
objc_property_t * propertyList = class_copyPropertyList([self class], &count);
for (unsigned int i=0; i<count; i++) {
const char * propertyname = property_getName(propertyList[i]);
NSLog(@"property----="">%@", [NSString stringWithUTF8String:propertyname]);
}
//获取方法列表//查看方法调用的顺序,因为可以动态的调整方法执行的书序
Method *methodList = class_copyMethodList([self class], &count);
for (unsigned int i = 0; i<count; i++) {
Method method = methodList[i];
NSLog(@"method----="">%@", NSStringFromSelector(method_getName(method)));
}
//获取成员变量列表
Ivar *ivarList = class_copyIvarList([self class], &count);
for (unsigned int i = 0; i<count; i++) {
Ivar myivar = ivarList[i];
const char *ivarname = ivar_getName(myivar);
NSLog(@"ivar----="">%@", [NSString stringWithUTF8String:ivarname]);
}
//获取协议列表
__unsafe_unretained Protocol **protocolList = class_copyProtocolList([self class], &count);
for (unsigned int i = 0; i<count; i++) {
Protocol *myprotocal = protocolList[i];
const char *protocolname = protocol_getName(myprotocal);
NSLog(@"protocol----="">%@", [NSString stringWithUTF8String:protocolname]);
}