Enabling Concurrency warnings in Xcode 15Published on: September 13, 2022
If you want to make sure that your code adopts Swift concurrency as correctly as possible in Swift 5.x, it's a good idea to enable the Strict Concurrency Checking (
SWIFT_STRICT_CONCURRENCY) flag in your project.
To do this, select your project's target and navigate to the
Build Settings tab. Make sure you select
All from the list of settings that is shown (
Basic is the default) and type
Strict Concurrency in the searchbar to find the
Strict Concurrency Checking build setting.
The screenshot below shows all the relevant parts for you to see:
The default value for this setting is
Minimal which boils down to the Compiler only checking explicit
Sendable annotations amongst other things. This setting is the least restrictive and enforces as little of Swift Concurrency's constraints as possible for the time being.
You can bump your checking to
Targeted which will enforce
Sendable and actor-isolation checks in your code, and it will explicitly very that
Sendable constraints are met when you mark one of your types as
Sendable. This mode is essentially a bit of a hybrid between the behavior that's intended in Swift 6, and what's allowed now. You can use this mode to have a bit of checking on your code that uses Swift Concurrency without too much warnings and / or errors in your current codebase.
Complete you will get the full suite of concurrency constraints, essentially as they will work in Swift 6. Personally I would recommend enabling this setting for new projects where you want all of your code to be properly checked immediately. In an existing codebase this mode might be a little too strict, but on the other hand it will flag lots of things that will be mandatory in Swift 6.
Update: At the moment, it looks like Apple will allow developers to continue using Sendability checking from Swift 5 with the Swift 6 compiler for a very long time. To me, this says that there's still some gaps and complexities in getting all codebases to be compliant with strict Sendable checks.