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

Discussion in 'iOS Programming' started by moonman239, Jun 20, 2015.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    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?
     
  2. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    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?
     
  3. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    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.
     
  4. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #5
    +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.
     

Share This Page