Which is better way of handling callback in iOS -


i have created custom network handler managing server calls application. internally uses nsurlconnection , callback function block once data fetch complete. current can set callback method or callback codeblock. wanted understand 1 better , why.

option 1 :

basenetworkhelper * helper = [[basenetworkhelper alloc] initwithurl:@"request/url/as/string" action:@"action/for/request" params:params]; [helper addfinishaction:self sel:@selector(markreadfinished:)]; 

is way arc warning when call callback method once action complete. bellow.

if (_target) {         if ([_target respondstoselector:selector]) {             [_target performselector:selector withobject:rdata];         }     } 

option 2:

basenetworkhelper * helper = [[basenetworkhelper alloc] initwithurl:@"request/url/as/string" action:@"action/for/request" params:params]; [helper startdownload:^(nsdata *data, nserror *error) {             // business logic response handling / error handling         }]; 

thanks.

the block places completion code in same context code begins request, makes easier read , captures values -- initialized -- you'll want on completion.

if opt target/selector approach, according this, there's way work around warning in llvm >=3. (see highly upvoted answer down page bit).


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -