objective c - What is the difference between calling the methods in iOS -


suppose call with

[self methodname]  

and other with

[self performselector:@selector(methodname) withobject:nil]; 

no difference whatsoever.

straight documentation of performselector:

the performselector: method equivalent sending aselector message directly receiver. example, 3 of following messages same thing:

id myclone = [anobject copy]; id myclone = [anobject performselector:@selector(copy)]; id myclone = [anobject performselector:sel_getuid("copy")]; 

while there's no difference in specific case, however, reason why performselector: exists allows invoking arbitrary selector may not available @ compile time, discussed in doc:

however, performselector: method allows send messages aren’t determined until runtime. variable selector can passed argument:

sel mymethod = findtheappropriateselectorforthecurrentsituation(); [anobject performselector:mymethod]; 

the considerations above apply 2 variants performselector:withobject:, performselector:withobject:withobject:.

please note doesn't hold true set of methods, namely

  • performselector:withobject:afterdelay:
  • performselector:withobject:afterdelay:inmodes:
  • performselectoronmainthread:withobject:waituntildone:
  • performselectoronmainthread:withobject:waituntildone:modes:
  • performselector:onthread:withobject:waituntildone:
  • performselector:onthread:withobject:waituntildone:modes:
  • performselectorinbackground:withobject:

further info here: does performselector perform right away or scheduled performed?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -