Last active
December 25, 2015 16:09
-
-
Save iamleeg/7004314 to your computer and use it in GitHub Desktop.
Spelunking, dispatch style
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
#import <Foundation/Foundation.h> | |
#import <dispatch/dispatch.h> | |
#import <objc/runtime.h> | |
void printMethodList(Class cls, const char *prefix) | |
{ | |
const char *className = class_getName(cls); | |
unsigned int countOfMethods; | |
Method *methodList = class_copyMethodList(cls, &countOfMethods); | |
for(unsigned int i = 0; i < countOfMethods; i++) | |
{ | |
SEL aSelector = method_getName(methodList[i]); | |
const char *selectorName = sel_getName(aSelector); | |
printf("%s[%s %s]\n", prefix, className, selectorName); | |
} | |
free(methodList); | |
} | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
id q = (__bridge id)queue; | |
Class DispatchQueue = [q class]; | |
Class ThisClass = DispatchQueue; | |
do { | |
printMethodList(ThisClass, "-"); | |
Class MetaClass = object_getClass(ThisClass); | |
printMethodList(MetaClass, "+"); | |
ThisClass = class_getSuperclass(ThisClass); | |
} while (ThisClass != Nil); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment