Is dataWithContentsOfURL bad when starting an application?

I am making an application that accesses some data the first time it is launched and then displays it. I downloaded this data like this:

NSData *data = [NSData dataWithContentsOfURL:url];

This is bad? Right now I have installed a method that contains this to work in the background thread using GCD, but I heard that since it dataWithContentsOfURLis synchronous, this is bad. Any opinions on this?

+5
source share
2 answers

This is bad if you run it in the main user interface thread. This will block the responsiveness of your application, which is bad, but it is even worse at startup.

. , (GCD dispatch_async) NSUrlConnection.

GCD , ( ) :

GCD, ,

NSUrlConnection. . initWithRequest:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

+5

, .
, , . . - . , :

+dataWithContentsOfURL:options:error: 

, - .

+3

All Articles