Frage

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?

War es hilfreich?

Lösung

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 

Andere Tipps

AFAIK, using the selector is a way to declare the callback method as what we did on Java, C#, ... Suppose that you develop library A, which do an asynchronous calculate and return result whenever it done. At development time, you don't know what call back method you should call whenever the calculating done. So you can make the library get an selector as input parameter and use performSelector later to invoke callback methods.

Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top