在arc下使用objc_getClassList

时间:2012-01-04 16:57:22

标签: iphone ios automatic-ref-counting objective-c-runtime

是否有人设法在arc下使用objc_getClassList,而不是为相关文件关闭弧线?

基本问题是其中一个参数是C类指针类。

1 个答案:

答案 0 :(得分:34)

此代码应在ARC下运行:

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);
}