Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using objc_getClassList under arc

Has anybody managed to use objc_getClassList under arc, short of turning arc off for the file in question?

The fundamental problem is that one of the parameters is a C array of Class pointers.

like image 268
William Jockusch Avatar asked Jan 04 '12 16:01

William Jockusch


1 Answers

This code should work under 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);
}
like image 165
Ole Begemann Avatar answered Sep 28 '22 18:09

Ole Begemann