What is IMP in Objective C?
Ask by Tarun Kumar
Updated 19 Sep 2020
It’s the C type of a method implementation pointer, a function pointer to the function that implements an Objective-C method. It is defined to return id and takes two hidden arguments, self and _cmd :
typedef id (*IMP)(id self,SEL _cmd,…);
To access IMP, the message ‘methodForSelector’ can be used:
IMP letsDoSomething = [aObject methodForSelector:@selector(doSomething)];
Now, the method addressed by IMP can be called by dereferencing the IMP,
letsDoSomething(aObject, @selector(doSomething));
And hence, these calls are similar,
[aObject doSomething];
[aObject performSelector:@selector(doSomething)];
[aObject performSelector:NSSelectorFromString(@”doSomething”)];