How do I call methods in a class that I created dynamically with NSClassFromString?-Collection of common programming errors

An easier and fancier solution than NSInvocation 🙂

Class mediaClass = NSClassFromString(kMediaClassName);
if(mediaClass){
    id mediaObject = class_createInstance(mediaClass,0);
    objc_msgSend(mediaObject, @selector(doSomethingWith:andWith:alsoWith:), firstP, secondP,thirdP);
}

Explanation:

class_createInstance(mediaClass,0); does exactly the same as [[mediaClass alloc] init]; if you need to autorelease it, just do the usual [mediaObject autorelease];

objc_msgSend() does exactly the same as performSelector: method but objc_msgSend() allows you to put as many parameters as you want. So, easier than NSInvocation right? BTW, their signature are:

id class_createInstance(Class cls, size_t extraBytes)
id objc_msgSend(id theReceiver, SEL theSelector, ...)

For more info you can refer the Objective-C Runtime Reference