1 #import "ITCategory-NSObject.h"
2 #import <objc/objc-runtime.h>
4 @implementation NSObject (ITFoundationCategory)
6 + (NSArray *)subclasses
8 NSMutableArray *tempArray;
13 int count, newCount, index;
14 tempArray = [[NSMutableArray allocWithZone:nil] initWithCapacity:12];
18 count = objc_getClassList(NULL, 0);
20 classes = malloc(sizeof(Class) * count);
22 newCount = objc_getClassList(classes, count);
23 while (count < newCount) {
26 classes = malloc(sizeof(Class) * count);
28 newCount = objc_getClassList(classes, count);
35 const Class thisClass = [self class];
37 for (index = 0; index < count; ++index) {
38 superClass = class_getSuperclass((*current));
41 if (superClass == thisClass) {
42 [tempArray addObject:*current];
45 superClass = class_getSuperclass(superClass);
52 resultArray = [NSArray arrayWithArray:tempArray];
58 + (NSArray *)directSubclasses
60 NSMutableArray *tempArray;
64 int count, newCount, index;
65 tempArray = [[NSMutableArray allocWithZone:nil] initWithCapacity:12];
69 count = objc_getClassList(NULL, 0);
71 classes = malloc(sizeof(Class) * count);
73 newCount = objc_getClassList(classes, count);
74 while (count < newCount) {
77 classes = malloc(sizeof(Class) * count);
79 newCount = objc_getClassList(classes, count);
86 const Class thisClass = [self class];
89 for (index = 0; index < count; ++index) {
90 if (class_getSuperclass((*current)) == thisClass) {
91 [tempArray addObject:*current];
97 resultArray = [NSArray arrayWithArray:tempArray];