sindresorhus / Defaults

💾 Swifty and modern UserDefaults
https://swiftpackageindex.com/sindresorhus/Defaults/documentation/defaults
MIT License
1.93k stars 115 forks source link

Sendable conformance for Key #167

Closed Wouter01 closed 5 months ago

Wouter01 commented 5 months ago

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.