新建一個(gè)Animal類 ?給類添加一些成員變量、屬性、和方法。

在控制器里面使用該類 并 給相應(yīng)的變量賦值 ?
? //獲取類方法和屬性列表
? ? Animal *mal=[[Animal alloc]init];
? ? [malsetValue:@"大象" forKey:@"name"];
? ? [malsetValue:@"陸地" forKey:@"type"];
? ? [malsetValue:@"grayColor" forKey:@"color"];
? ? //屬性
?? ? mal.tName=@"動(dòng)物";
?? ? mal.wailt=@60;
下面 我們就開(kāi)始用runtime來(lái)獲取一下該類的一些成員變量 屬性 和方法列表?
//獲取 屬性 方法? 成員 變量? 列表
-(void)runtimeList:(Animal*)animal
{
? ? unsigned? int ?count;
? ? //獲取屬性列表
? ? objc_property_t? *propertys=class_copyPropertyList([animal class], &count);
? ? for(NSIntegerindex=0; index
? ? {
? ? ? ? constchar* propertyName=property_getName(propertys[index]);
? ? ? ? NSString *name=[NSString stringWithUTF8String:propertyName];
? ? ? ? //打印屬性和對(duì)應(yīng)的值值
? ? ? ? NSLog(@"%@ -------%@",name,[animal valueForKey:name]);
? ? }
? ? free(propertys);
? ? //獲取成員變量列表
? ? Ivar? *ivars=class_copyIvarList([animalclass], &count);
? ? for(NSIntegerindex=0; index
? ? ? ? const? char* ivarName=ivar_getName(ivars[index]);
? ? ? ? NSString *name=[NSString? stringWithUTF8String:ivarName];
? ? ? ? //打印成員變量和值
? ? ? ? NSLog(@"%@---------%@",name ,[animal valueForKey:name]);
? ? }
? ? free(ivars);
? ? //獲取方法列表
? ? Method*methedList=class_copyMethodList([animalclass], &count);
? ? for(NSIntegerindex=0; index
? ? ? ? SEL? methodName=method_getName(methedList[index]);
? ? ? ? constchar* name=sel_getName(methodName);
? ? ? ? NSString *strName=[NSString stringWithUTF8String:name];
? ? ? ? NSLog(@"%@",strName);
? ? }
? ? free(methedList);
? ? //獲取協(xié)議列表
? ? __unsafe_unretained? Protocol ** proList= class_copyProtocolList([animal class], &count);
? ? for(NSIntegerindex=0; index
? ? ? ? Protocol*proName=proList[index];
? ? ? ? constchar*protocolName=protocol_getName(proName);
? ? ? ? NSString *name=[NSString stringWithUTF8String:protocolName];
? ? ? ? NSLog(@"%@",name);
? ? }
}
控制臺(tái) 打印?
