Swift 5.10 adds new warnings related to strict concurrency. The Defaults.Key class currently lacks Sendable conformance, generating lots of warnings of the following kind when defining keys:
Static property 'someKey' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6
The most logical thing would be to make Key a struct instead of a class, but I'm assuming inheritance is needed to get the current static property behavior. I'm not sure, but I think it's safe to add @unchecked Sendable conformance to _AnyKey. Checked Sendable conformance will give a warning as the class is not final, and UserDefaults is not marked Sendable. The docs state that it is thread safe though, making me believe adding @unchecked Sendable is fine. The _AnyKey class and Key class contain no mutable state, which is also fine for Sendable.
Swift 5.10 adds new warnings related to strict concurrency. The
Defaults.Key
class currently lacks Sendable conformance, generating lots of warnings of the following kind when defining keys:The most logical thing would be to make Key a struct instead of a class, but I'm assuming inheritance is needed to get the current static property behavior. I'm not sure, but I think it's safe to add
@unchecked Sendable
conformance to_AnyKey
. Checked Sendable conformance will give a warning as the class is not final, and UserDefaults is not marked Sendable. The docs state that it is thread safe though, making me believe adding@unchecked Sendable
is fine. The_AnyKey
class andKey
class contain no mutable state, which is also fine forSendable
.