billwang1990
billwang1990

Reputation: 627

Objective-C call a class method in runtime which the class is private

I got a .framework file, and I use class-dump to know there is a class named ABC inside and don't expose anything, and ABC have a useful method for me, so I wonder know can I call ABC's method dynamic by Objective-C runtime.

Wait for your help!

Upvotes: 0

Views: 634

Answers (1)

rckoenes
rckoenes

Reputation: 69459

To create an instance of class if by it's name use NSClassFromString:

 Class myPrivateClass = NSClassFromString(@"MyPrivateClass");
 myPrivateClass  *myPrivateObj = [myPrivateClass new];

Now that you have the instance of the class call the select, to make it easier you can cast the instance to NSObject

 [(NSObject *)myPrivateClass performSelector:@selector(description) withObject:nil];

Or the class method:

  [myPrivateClass performSelector:@selector(description)];

Here I'm calling description on the instance and class.

Upvotes: 2

Related Questions