Using -performSelector: vs. just calling the method

后端 未结 5 1915
陌清茗
陌清茗 2020-11-28 18:26

I\'m still kind of new to Objective-C and I\'m wondering what is the difference between the following two statements?

[object performSelector:@selector(doSom         


        
5条回答
  •  情歌与酒
    2020-11-28 19:00

    Basically performSelector allows you to dynamically determine which selector to call a selector on the given object. In other words the selector need not be determined before runtime.

    Thus even though these are equivalent:

    [anObject aMethod]; 
    [anObject performSelector:@selector(aMethod)]; 
    

    The second form allows you to do this:

    SEL aSelector = findTheAppropriateSelectorForTheCurrentSituation();
    [anObject performSelector: aSelector];
    

    before you send the message.

提交回复
热议问题