Give your simulator superpowers

RocketSim: An Essential Developer Tool
as recommended by Apple

Win a copy of The macOS App Icon Book with thisfree giveaway

Concurrency-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 by removing mutability or conforming to Sendable is essential. As a developer, you must prevent data races since they can make your ...

Unit 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 be aware of when validating asynchronous code. If you're new to async/await, I encourage you first to read Async ...

Thread 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 misunderstand how actors dispatch to threads in non-async contexts. It's an essential understanding to avoid unexpected crashes. Before ...

@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 asynchronous code, mainly using closures. On our road to Swift 6, we must prepare our projects for strict concurrency checks done by the ...

Swift 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 major version bump. The Swift development team shared their focus areas for 2023 and released ...

MainActor 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 on the main thread, which can sometimes be challenging when using several background threads. Using the ...

Detached 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 disconnecting potentially relevant tasks. While it sounds terrible to disconnect from structured concurrency, there are still examples of use cases ...

Task 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 responses into a single response object. Read my article about tasks first if you're new to ...

Sendable 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 messages. Before diving into the topic of sendables, I encourage you to read up on my articles around async/await, actors, and ...

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 asynchronous variant of the regular sequence we're familiar with in Swift. Like you won't often create your custom Sequence ...

AsyncThrowingStream and AsyncStream explained with code examples

AsyncThrowingStream and AsyncStream are part of the concurrency framework introduced in Swift 5.5 due to SE-314. Async streams allow you to replace existing code that is based on closures or Combine publishers. Before diving into details around throwing streams, I recommend reading my article covering async-await if you didn't do ...