The tale of Grand Central Dispatch...
Once upon a time, the amount of work that could be done on a computer was limited to the speed of the computer's processor. It could only process one task at a time until said task was done, then it could move to the next task.
As technology advanced, processors were developed with multiple cores - which allowed software to do many things simultaneously (a.k.a concurrency) as opposed to one after the other, by creating multiple threads (a path that executes code).
When utilizing threads the application had to know how many threads could be created, based on the amount of processor cores. Also, developers had to make sure that their threads were executed in order and avoid interfering with each other. Thankfully, iOS developers of today have an easier job when dealing with multithreading.
iOS does not rely on threads upfront. Instead of taking care of threads ourselves we add our tasks ("some work your application needs to process") to queues (a block of code that can be run asynchronously or synchronously). Functions (mostly closures) are lined up in a queue, then those functions are pulled off the queue and executed on an associated thread.
Oh yeah, quick break down on (some of) the type of queues :
- Serial queue: function on top (front of the line/queue) gets pulled off, runs to completion, then the next one gets pulled off.
- Concurrent queue: multiple things going on at once/doing a task behind the scene and continuing the main work, while the background work continues. A concurrent queue pulls the top task off the queue, starts running it and if it has more resources it takes a next task and starts running it on a different thread.
- The most important queue is the Main Queue (which functions as a serial queue - this allows the UI to be presented in an orderly fashion) and this is where all UI activity must happen.
Why is this important? Because I guarantee that as an iOS Developer you will encounter this! So I suggest you get cozy with Apple's guide for concurrency programming and get down with grand central dispatch.