Created
February 29, 2012 23:00
-
-
Save febeling/1945195 to your computer and use it in GitHub Desktop.
objective-c instrospection
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 <objc/runtime.h> | |
-(void)dumpInfo | |
{ | |
Class clazz = [self class]; | |
u_int count; | |
Ivar* ivars = class_copyIvarList(clazz, &count); | |
NSMutableArray* ivarArray = [NSMutableArray arrayWithCapacity:count]; | |
for (int i = 0; i < count ; i++) | |
{ | |
const char* ivarName = ivar_getName(ivars[i]); | |
[ivarArray addObject:[NSString stringWithCString:ivarName encoding:NSUTF8StringEncoding]]; | |
} | |
free(ivars); | |
objc_property_t* properties = class_copyPropertyList(clazz, &count); | |
NSMutableArray* propertyArray = [NSMutableArray arrayWithCapacity:count]; | |
for (int i = 0; i < count ; i++) | |
{ | |
const char* propertyName = property_getName(properties[i]); | |
[propertyArray addObject:[NSString stringWithCString:propertyName encoding:NSUTF8StringEncoding]]; | |
} | |
free(properties); | |
Method* methods = class_copyMethodList(clazz, &count); | |
NSMutableArray* methodArray = [NSMutableArray arrayWithCapacity:count]; | |
for (int i = 0; i < count ; i++) | |
{ | |
SEL selector = method_getName(methods[i]); | |
const char* methodName = sel_getName(selector); | |
[methodArray addObject:[NSString stringWithCString:methodName encoding:NSUTF8StringEncoding]]; | |
} | |
free(methods); | |
NSDictionary* classDump = [NSDictionary dictionaryWithObjectsAndKeys: | |
ivarArray, @"ivars", | |
propertyArray, @"properties", | |
methodArray, @"methods", | |
nil]; | |
NSLog(@"%@", classDump); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment