Chapter 6. Structured Concurrency
The term concurrency refers to the ability of a computer program to do more than one thing at the same time. When you’re programming iOS, the runtime uses concurrency constantly; if it didn’t, your app would be less responsive to the user — perhaps completely unresponsive.
For the most part, the various Cocoa frameworks use concurrency behind the scenes on your behalf; you don’t have to worry about concurrency because the frameworks are worrying about them for you.
For instance, suppose your app is downloading something from the network. This download doesn’t happen all by itself; somewhere, someone is running code that interacts with the network and obtains data. Yet none of that interferes with your code, or prevents the user from tapping and swiping things in your interface. The networking code runs “in the background.” That’s concurrency in action.
Nevertheless, sometimes you need to be concerned with concurrency explicitly. For example:
- Receiving a communication from background code
-
Let’s say your app has asked to download something from the network. Presumably, that’s because you want that thing. If you’re downloading an image, the goal might be to display that image in your interface, or to store that image as a file saved to disk. The runtime, in code that you can’t see, does the downloading in the background, but eventually it will finish; it has obtained the image. Now your code needs a way to receive that image so that it can do ...
Get iOS 15 Programming Fundamentals with Swift now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.