Skip to content

Instantly share code, notes, and snippets.

@fahied
Created November 6, 2014 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahied/5e46ecf65ea0a9e11e61 to your computer and use it in GitHub Desktop.
Save fahied/5e46ecf65ea0a9e11e61 to your computer and use it in GitHub Desktop.
Listing Methods at Runtime in Objective C
-(void)listAllClassMethods
{
// Iterate over the class and all superclasses
Class currentClass = [self class];
while (currentClass) {
// Iterate over all instance methods for this class
unsigned int methodCount;
Method *methodList = class_copyMethodList(currentClass, &methodCount);
unsigned int i = 0;
for (; i < methodCount; i++) {
NSLog(@"%@ - %@", [NSString stringWithCString:class_getName(currentClass) encoding:NSUTF8StringEncoding], [NSString stringWithCString:sel_getName(method_getName(methodList[i])) encoding:NSUTF8StringEncoding]);
}
free(methodList);
currentClass = class_getSuperclass(currentClass);
}
}
// source - http://pagesofinterest.net/blog/2012/01/listing-methods-at-runtime-in-objective-c/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment