문제

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?

도움이 되었습니까?

해결책

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 

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top