The Grand Central Dispatch (GCD) is a big topic. The first thing I wanted to try when I started to learn it a few months ago is set of asynchronous operations like image downloads. Check out my old sample how to get Asynchronous UIImage from web or this one if you need to download a really big file in the background on the app launch.
Current sample is for situation when you need to download a set of files, so you must have a queue. The magic of GCD is that it manages queues automatically depending of available resources and their priorities. GCD does that efficiently because of low level implementation and Bloc
- has a predefined set of urls to download
- creates a GCD queue and starts to download images
- shows each image as soon as it’s available with appearing–dissappearing animation
Тhe demo result is nice Category UIImageView+DispatchLoad:
Note, this is just a sample how GCD works with queues and asynchronous operations. Don’t use it in production because it’s usually need to cancel and re-prioritize network downloads. GCD approach is nice for local operations like saving a big file to disk. GCD lets us to keep UI smooth while heavy operations – that’s the main point.