Object

获取所有子类

1
2
3
4
5
6
/**
获取所有子类

@return 所有子类
*/
+ (NSArray *)ax_allSubclasses;

实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
+ (NSArray *)ax_allSubclasses{
NSMutableArray *subclasses = [NSMutableArray array];
unsigned int numOfClasses;
Class *classes = objc_copyClassList(&numOfClasses);
for (unsigned int ci = 0; ci < numOfClasses; ci++) {
Class superClass = classes[ci];
do{
superClass = class_getSuperclass(superClass);
} while (superClass && superClass != self);

if (superClass)
{
[subclasses addObject: classes[ci]];
}
}
free(classes);
return subclasses;
}



评论

有疑问请前往本项目的【Issue】页面搜索问题,如果没有相关问题,点击【New issue】进行提问。