0

I have created a custom Network handler for managing all server calls from Application. This internally uses NSURLConnection and callback a function block once data fetch is complete. Current I can set the callback method or a callback CodeBlock. I wanted to understand which one is better and 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 this way I get ARC warning when I call the callback method once action is complete. like 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 for response handling / error handling
        }];

Thanks.

Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
Vishal Kardode
  • 961
  • 2
  • 8
  • 25

1 Answers1

0

The block places the completion code in the same context as the code that begins the request, which makes it easier to read and often captures the values -- already initialized -- you'll want on completion.

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

Community
  • 1
  • 1
danh
  • 62,181
  • 10
  • 95
  • 136