Search code examples
ios5methodsperformselector

When and why to use performSelector - iOS


I have been trying to figure out why and how to use performSelector. I did come across Apple Docs. However, I am not able to fully understand it.

Would anyone be able to help me out in explaining this?


Solution

  • From Apple's documentation:

    the performSelector: method allows you to send messages that aren’t determined until runtime

    Longer story:

    You can send messages to objects without prior knowledge of whether the object implements this particular method. For example:

    NSString *astring = @"test";
    
    [test dance]; // Doesn't compile
    [test performSelector:@selector(dance)]; // Doesn't make sense but compiles