More flexible "performselector"

Source: Internet
Author: User

I want to invoke a selector of a method that has the usual nserror ** argument:

 -(  Int  )  Getitemssince  :(  Nsdate     *)  When  Dataselector  :(  Sel  )  Getdataselector Error  :(  Nserror  **)  Outerror  { 
Nsarray   * Data =   Nil ;
If ([ Service respondstoselector : Getdataselector ])   {
Data =   [ Service performselector : Getdataselector withobject : When Withobject : Outerror ];
// Etc.
 

... Which the compiler doesn't like:

Warning:Passing argument3Of'Your mselector: withobject :' FromIncompatible pointer type

 
¥ ¥ ¥
 
Check out nsinvocation, which gives you a more flexible way to "performselector ".
 If     ([  Service respondstoselector  :  Getdataselector ])     {  
Nsarray   * Data ;
Nsinvocation   * Invocation =   [ Nsinvocation Invocationwithmethodsignature :
[ Service methodsignatureforselector : Getdataselector ];
[ Invocation settarget : Delegate ];
[ Invocation setselector : Getdataselector ];
// Note: indexes 0 and 1 correspond to the implicit arguments self and _ cmd,
// Which are set using settarget and setselector.
[ Invocation setargument : When Atindex : 2 ];  
[ Invocation setargument : Outerror atindex : 3 ];
[ Invocation invoke ];
[ Invocation getreturnvalue :& Data ];
}
 
//////////////////////////////////////// ////
 
Perform selector calls more than two parameters
 
You can also put all the parameters in the dictionary, such as nsnotification or nstimer userinfo.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.