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:
Tarun Kumar
18-Jul-2015It’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”)];