forked from parmanoir/jscocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSCocoaHelper.m
56 lines (45 loc) · 1.18 KB
/
JSCocoaHelper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// JSCocoaHelper.m
// JSCocoa
//
// Created by Patrick Geiller on 18/09/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "JSCocoaHelper.h"
@implementation JSCocoaHelper
/*
List of registered classes
http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/objc_getClassList
*/
+ (NSString*)classList
{
id list = [NSMutableArray array];
int numClasses;
Class * classes = NULL;
classes = NULL;
numClasses = objc_getClassList(NULL, 0);
if (numClasses > 0 )
{
classes = malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
int i;
for (i=0; i<numClasses; i++)
{
Class c = classes[i];
id str;
if (!class_respondsToSelector(c, @selector(superclass)))
{
str = [NSString stringWithFormat:@"%s", class_getName(c)];
}
else
{
const char* className = (const char*)class_getName([c superclass]);
str = [NSString stringWithFormat:@"%s %s", class_getName(c), (!className || strcmp(className, "nil")) == 0 ? "" : className];
}
[list addObject:str];
}
free(classes);
}
return [list componentsJoinedByString:@"\n"];
}
@end