NSURLConnection synchronous vs. asynchronous

Synchronous means that you trigger your NSURLConnection request and wait for it to be done.

Asynchronous means that you can trigger the request and do other stuff while NSURLConnectiondownloads data.

Which is “best”?

Synchronous is very straightforward: you set it up, fire it, and wait for the data to come back. But your application sits there and does nothing until all the data is downloaded, some error occurs, or the request times out. If you’re dealing with anything more than a small amount of data, your user will sit there waiting, which will not make for a good user experience.

Asynchronous requires just a little more work, but your user can do other stuff while the request does its thing, which is usually preferable. You set up some delegate methods that let you keep track of data as it comes in, which is useful for tracking download progress. This approach is probably better for most usage cases.

You can do both synchronous and asynchronous requests with NSURLConnection. Apple’sdocumentation provides a clear explanation of the two approaches and delegate methods required for the latter approach.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s