Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
So, I stumbled across a method called "methodForSelector", which returns an IMP. Suppose I have two methods, A and B. B is supposed to cause the code in A's method definition to be fired after a delay, but needs to pass a double value as an argument; therefore B cannot call the method or A's performSelector method, and B also cannot use an NSInvocation. But if it can use an IMP, then what code do I need to put in to B?
 
IMPs are part of the IMP Caching optimization strategy, as described here http://www.mulle-kybernetik.com/artikel/Optimization/opti-3.html

Here's a simpler explanation:

http://stackoverflow.com/questions/2650190/objective-c-and-use-of-sel-imp

Thanks. So, to answer my question, I can just call an IMP like a C function - if I have an IMP that I refer to as theImplementation, I call it like so:
Code:
theImplementation(arguments)
I do have a question. Is there any reason not to use an IMP to call a method?
 
IMPs are a little complicated to use. In most cases the only reason to use them is for optimization. The method calls will be a little faster. The reason not to use them is they usually gain you nothing and are a bit of a pain to use. They also make your code more complicated and harder for others and yourself to understand.

These days you could often use a block for the kind of code you mention at the start of this thread.
 
+1 on the use of blocks, if you do a bit of research you'll find the ObjC and the APIs use blocks all over the place and they are very powerful.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.