Invoking an Objective-C method by name

You can use something like the following:

SEL selector = NSSelectorFromString(methodName);
[myObject performSelector:selector];

There are also performSelector:withObject:, and performSelector:withObject:withObject: methods if you need to pass parameters.


In order to perform methods invocation in reflection on objetive c just use this quick recipe. objC enabling us checking if an object supports a particular interface at runtime, This invocation happens dynamically if exists.

Class classAPI = NSClassFromString(@"yourClassName");
SEL methodToPerformSelector = NSSelectorFromString(@"yourMethodName:");
NSMethodSignature *methodSignature = [classAPI methodSignatureForSelector:methodToPerformSelector];
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[myInvocation setTarget:classAPI];
[myInvocation setSelector:methodToPerformSelector]

/* if you have an argument */
[myInvocation setArgument:&someArgumentToAddToYourMethod atIndex:argumentIndexInMethod];
[myInvocation retainArguments];

[myInvocation invoke];