object-c 动态反射
最近要做一个ios平台的快速开发框架 需要用到高级语言的反射的功能:总结了一下object-c的反射功能:
1:
Class clazz = ;
u_int count;
Ivar* ivars = class_copyIvarList(clazz, &count);
NSMutableArray* ivarArray = ;
for (int i = 0; i < count ; i++)
{
const char* ivarName = ivar_getName(ivars);
];
}
free(ivars);
objc_property_t* properties = class_copyPropertyList(clazz, &count);
NSMutableArray* propertyArray = ;
for (int i = 0; i < count ; i++)
{
const char* propertyName = property_getName(properties);
];
}
free(properties);
Method* methods = class_copyMethodList(clazz, &count);
NSMutableArray* methodArray = ;
for (int i = 0; i < count ; i++)
{
SEL selector = method_getName(methods);
const char* methodName = sel_getName(selector);
];
}
free(methods);
NSDictionary* classDump = [NSDictionary dictionaryWithObjectsAndKeys:
ivarArray, @"ivars",
propertyArray, @"properties",
methodArray, @"methods",
nil];
NSLog(@"%@", classDump);
2:
NSString* className = @"Car";
id* p = ;
;
3:
Class cls = objc_get_class( "Test" );
id obj = class_create_instance( cls );
[ obj free ];
页:
[1]