AsyncSequence explained with Code Examples
AsyncSequence is part of the concurrency framework and the SE-298 proposal. Its name implies it’s a type providing asynchronous, sequential, and iterated access to its elements. In other words: it’s an...
View ArticleSendable and @Sendable closures explained with code examples
Sendable and @Sendable are part of the concurrency changes that arrived in Swift 5.5 and address a challenging problem of type-checking values passed between structured concurrency constructs and actor...
View ArticleTask Groups in Swift explained with code examples
Task Groups in Swift allow you to combine multiple parallel tasks and wait for the result to return when all tasks are finished. They are commonly used for tasks like combining multiple API request...
View ArticleDetached Tasks in Swift explained with code examples
Detached tasks allow you to create a new top-level task and disconnect from the current structured concurrency context. You could argue that using them results in unstructured concurrency since you’re...
View ArticleMainActor usage in Swift explained to dispatch to the main thread
MainActor is a new attribute introduced in Swift 5.5 as a global actor providing an executor which performs its tasks on the main thread. When building apps, it’s essential to perform UI updating tasks...
View ArticleSwift 6: Preparing your Xcode projects for the future
Swift 6 will be the next major release of Apple’s programming language and aims to create a fantastic development experience. Many of the latest features we know today are part of the road toward this...
View Article@preconcurrency: Incremental migration to concurrency checking
The @preconcurrency attribute is part of the tools that help you incrementally migrate to strict concurrency checking. When async/await was introduced by Apple, we were writing non-structured...
View ArticleThread dispatching and Actors: understanding execution
Actors ensure your code is executed on a specific thread, like the main or a background thread. They help you synchronize access to mutable states and prevent data races. However, developers commonly...
View ArticleUnit testing async/await Swift code
Unit tests allow you to validate code written using the latest concurrency framework and async/await. While writing tests doesn’t differ much from synchronous tests, there are a few crucial concepts to...
View ArticleConcurrency-safe global variables to prevent data races
Concurrency-safe global variables help you prevent data races and allow you to solve strict-concurrency-related warnings. Since you can access global variables from any context, ensuring access is safe...
View Article