Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

iOS How do I cause an IMP to fire? How do I make it fire after a delay?

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,530
22
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?
 

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,530
22
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?
 
Comment

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Comment

1458279

Suspended
May 1, 2010
1,601
1,521
California
+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.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.