The Main Thread
iOS devices can run multiple chunks of code simultaneously. These computations proceed in parallel, so this is referred to as parallel computing. A common way to express this is by representing each computation with a different thread of control.
So far in this book, all your code has been running on the main thread. The main thread is sometimes referred to as the UI thread, because any code that modifies the UI must run on the main thread.
When the web service completes, you want it to update the image view. To avoid blocking the main thread with long-running tasks, URLSessionDataTask runs on a background thread, and the completion handler is called on this thread. You need a way to force code to run on ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access