Forum Navigation
You need to log in to create posts and topics.

Accessing private APIs

Posted by: bernfbe <bernfbe@...>

For interest, the following reveals all methods, properties, etc. for a class, some of which are private.

Bernie

// ---------------
include "NSLog.incl"

void local fn ShowClassInfo( classString as CFStringRef )
'~'1
BeginCCode
NSString *classStr = (__bridge NSString *)classString;
Class class = NSClassFromString(classStr);

NSLog(@"Class Methods");
NSLog(@"-------------");
int unsigned numClassMethods;
Method *classMethods = class_copyMethodList(objc_getMetaClass([classStr UTF8String]), &numClassMethods);
for (unsigned int i = 0; i < numClassMethods; i++) {
NSLog(@"%@", NSStringFromSelector(method_getName(classMethods[i])));
}
free(classMethods);

NSLog(@"");

NSLog(@"Instance Methods");
NSLog(@"----------------");
int unsigned numInstMethods;
Method *instMethods = class_copyMethodList(class, &numInstMethods);
for (unsigned int i = 0; i < numInstMethods; i++) {
NSLog(@"%@", NSStringFromSelector(method_getName(instMethods[i])));
}
free(instMethods);

NSLog(@"");

NSLog(@"Instance Vars");
NSLog(@"-------------");
int unsigned numIVars;
Ivar *ivarList = class_copyIvarList(class, &numIVars);
for (unsigned int i = 0; i < numIVars; i++) {
Ivar ivar = ivarList[i];
const char * name = ivar_getName(ivar);
NSLog(@"%s", name);
}

NSLog(@"");

NSLog(@"Properties");
NSLog(@"----------");
int unsigned numProperties;
objc_property_t *result = class_copyPropertyList(class,&numProperties);
for (unsigned int i = 0; i < numProperties; i++) {
objc_property_t o_t = result[i];
NSLog(@"%s",property_getName(o_t));
}
EndC
end fn

void local fn DoIt
'~'1
fn ShowClassInfo(@"CNPhoneNumber")
end fn

fn DoIt

HandleEvents