I want to download a lot of pictures from the server. How can I do this as fast as possible? Currently I am using:
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString: @"http://example.com/image.jpg"]]];
It is painfully slow. Is there any speed increase in downloading multiple images at the same time (asynchronously), and if so how many is too many?
You won't get a definitive answer to the optimal number of connections, because there is none. It just depends on several variables such as bandwidth, image size or your own patience. You need to measure this by yourself to get it right.
Doing asynchronous requests won't increase the downloading speed, but the user experience is way better. Seriously, you should consider doing it for any download that takes more than a second.
I always recommend using ASIHTTPRequest, it makes implementing things such as queues and progress bars easy.
Here's the simplest example from an asynchronous request using the library:
Update: This library will no longer be supported. From 1:
Nowadays I use AFNetworking for most of my projects.