Last active
October 31, 2018 21:40
-
-
Save uroboro/739178a8a73bdbc43457428029450b4d to your computer and use it in GitHub Desktop.
Generate a Graphviz diagram from an Objective-C class inheritance tree. Copy to tree.gv and run `dot -Tpng tree.png tree.gv`
This file contains hidden or 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
int numberOfClasses = objc_getClassList(NULL, 0); | |
Class * classList = (Class *)malloc(numberOfClasses * sizeof(Class)); | |
numberOfClasses = objc_getClassList(classList, numberOfClasses); | |
NSString * string = @"digraph cluster {\nrankdir=\"LR\"\n"; | |
for (int idx = 0; idx < numberOfClasses; idx++) { | |
Class clazz = classList[idx]; | |
if (some expression to filter results) { | |
NSString * str = [NSString stringWithFormat:@"%@ -> %@\n", | |
NSStringFromClass(class_getSuperclass(clazz)), | |
NSStringFromClass(clazz)]; | |
string = [string stringByAppendingString:str]; | |
} | |
} | |
free(classList); | |
string = [string stringByAppendingString:@"}"]; | |
NSLog(@"%@", string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment