Using the MainActor attribute to automatically dispatch UI updates on the main queue

Using the MainActor attribute to automatically dispatch UI updates on the main queue

One challenge when it comes to concurrency on Apple’s platforms is that an app’s UI can, for the most part, only be updated on the main thread. So, whenever we’re performing any kind of work on a background thread (either directly or indirectly), then we always have to make sure to jump back to the main queue before accessing any property, method, or function that has to do with rendering our UI.

[…]

Support Swift by Sundell by checking out this sponsor:

[…]

For much more on Swift’s new concurrency system, make sure to listen to my podcast conversation with Doug Gregor from Apple, and stay tuned to Swift by Sundell for many more articles on async/await, actors, and structured concurrency within the coming weeks and months.

[…]