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 sendingaselectormessage 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
Post a Comment