Created
October 6, 2011 14:52
-
-
Save mikeash/1267596 to your computer and use it in GitHub Desktop.
ARC and objc_getClassList do not get along
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang -framework Foundation -fobjc-arc test.m | |
#import <objc/runtime.h> | |
#import <stdio.h> | |
#import <stdlib.h> | |
int main(int argc, char **argv) | |
{ | |
@autoreleasepool | |
{ | |
int count = objc_getClassList(NULL, 0); | |
Class buffer[count]; | |
objc_getClassList(buffer, count); | |
for(int i = 0; i < count; i++) | |
{ | |
Class c = buffer[i]; | |
// see if c is in the NSObject hierarchy | |
BOOL isNSObj = NO; | |
// this will crash here when trying to retain a class which shouldn't be messaged | |
for(Class candidate = c; candidate != Nil; candidate = class_getSuperclass(candidate)) | |
{ | |
if(candidate == objc_getClass("NSObject")) | |
isNSObj = YES; | |
} | |
if(!isNSObj) | |
fprintf(stderr, "%s is not in the NSObject hierarchy\n", class_getName(c)); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment