WHAT IS IMP IN OBJECTIVE C?

Tarun Kumar

Total Post:107

Points:535
Posted by  Tarun Kumar
 747  View(s)
Ratings:
Rate this:
  1. Tarun Kumar

    Post:107

    Points:535
    What is IMP in Objective C?

    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”)];

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!