1 int objc_getClassList(Class *buffer, int bufferCount);
直接上高手的代码
int numClasses;
Class *classes = NULL;
classes = NULL;
numClasses = objc_getClassList(NULL, 0);
NSLog(@"Number of classes: %d", numClasses);
if (numClasses > 0 )
{
classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
for (int i = 0; i < numClasses; i++) {
NSLog(@"Class name: %s", class_getName(classes[i]));
}
free(classes);
}
2 Class * objc_copyClassList(unsigned int *outCount);
//盗几行代码
unsigned int outCount;
Class *classes = objc_copyClassList(&outCount);
for (int i = 0; i < outCount; i++) {
NSLog(@"==className=%s", class_getName(classes[i]));
}
free(classes);
3 Class objc_lookUpClass(const char *name);
Class class = objc_lookUpClass("AClass");//如果没有AClass返回nil
const char * className = class_getName(class);
NSLog(@"className=%s",className);
4 id objc_getClass(const char *name);
//实在是不好翻译
Discussion
objc_getClass
is different from [objc_lookUpClass
] in that if the class is not registered, objc_getClass
calls the class handler callback and then checks a second time to see whether the class is registered. [objc_lookUpClass
]does not call the class handler callback.
5 id objc_getMetaClass(const char *name); //用runtime 生成类时如果忘记注册了就会返回nill。
id obj = objc_getMetaClass("AClass");
NSLog(@"obj=:%@",obj);