Skip to content

Instantly share code, notes, and snippets.

@iamleeg
Last active December 25, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iamleeg/7004314 to your computer and use it in GitHub Desktop.
Save iamleeg/7004314 to your computer and use it in GitHub Desktop.
Spelunking, dispatch style
#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