Created
January 14, 2012 22:27
-
-
Save BennettSmith/1613121 to your computer and use it in GitHub Desktop.
Objective-C class category to print out names of all selectors on a class.
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
// | |
// NSObject+DumpClassInfo.h | |
// DumpSelectors | |
// | |
// Created by Bennett Smith on 1/14/12. | |
// Copyright (c) 2012 iDevelopSoftware, Inc. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (DumpClassInfo) | |
- (void)dumpClassInfo; | |
@end |
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
// | |
// NSObject+DumpClassInfo.m | |
// DumpSelectors | |
// | |
// Created by Bennett Smith on 1/14/12. | |
// Copyright (c) 2012 iDevelopSoftware, Inc. All rights reserved. | |
// | |
#import "NSObject+DumpClassInfo.h" | |
#import <objc/runtime.h> | |
static void dumpClassInfo(Class c, int inheritanceDepth) | |
{ | |
Class superClass = class_getSuperclass(c); | |
if (superClass != Nil) | |
{ | |
dumpClassInfo(superClass, (inheritanceDepth + 1)); | |
} | |
int i = 0; | |
unsigned int mc = 0; | |
const char* className = class_getName(c); | |
Method* mlist = class_copyMethodList(c, &mc); | |
for (i = 0; i < mc; i++) | |
{ | |
Method method = mlist[i]; | |
SEL methodSelector = method_getName(method); | |
const char* methodName = sel_getName(methodSelector); | |
const char *typeEncodings = method_getTypeEncoding(method); | |
char returnType[80]; | |
method_getReturnType(method, returnType, 80); | |
NSLog(@"%2.2d %s ==> %s (%s)", inheritanceDepth, className, methodName, (typeEncodings == Nil) ? "" : typeEncodings); | |
int ac = method_getNumberOfArguments(method); | |
int a = 0; | |
for (a = 0; a < ac; a++) { | |
char argumentType[80]; | |
method_getArgumentType(method, a, argumentType, 80); | |
NSLog(@" Argument no #%d: %s", a, argumentType); | |
} | |
} | |
} | |
@implementation NSObject (DumpClassInfo) | |
- (void)dumpClassInfo | |
{ | |
Class c = object_getClass(self); | |
dumpClassInfo(c, 0); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
method_getReturnType provides a single character "@" for objects. Any idea how to obtain the class of the object?