Created
March 27, 2012 05:17
-
-
Save kejinlu/2212718 to your computer and use it in GitHub Desktop.
dumpInfo For Objc 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
//你得 #import <objc/runtime.h> | |
-(void)dumpInfoForClass:(Class)clazz | |
{ | |
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
UINavigationController