Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous network operations in iOS 5

Everywhere I look, I see people explicitly using queues or run loops to do network operations. Should I still do that in iOS 5, or should I use NSURLConnection sendAsynchronousRequest:queue:completionHandler: instead? Is this the preferred method of doing network operations in iOS >= 5?

like image 226
rid Avatar asked Feb 20 '23 16:02

rid


1 Answers

I can't answer for others' preference, but I rolled my own < os5, and I strongly prefer the block operation. a) I'm never interested in intermediate results of the network operation, or the repetitive code to handle them, b) the block is retained, so I get fewer race conditions where some aspect of the delegate gets prematurely released, and c) I never get mixed up about what code is running when a particular operation finishes.

In short, it's a huge improvement in the NSURLConnection interface, IMO.

like image 61
danh Avatar answered Mar 06 '23 04:03

danh