Hey, thanks for your answer.
While I get the two points, I think UserDefaults does not have user info dictonaries. I get that custom subclasses can be problematic, but up to my knowledge, if an open class would be marked Sendable and someone tried to subclass it, swift would emit a warning that the subclass must also be Sendable. Also, certain other classes in Foundation (like NumberFormatter) are Sendable, despite being open.
In my particular case I cannot use the static UserDefaults.standard as I need to share the defaults within my app group.
Potential code snippet could be:
public final class Defaults: Sendable {
private let defaults: UserDefaults
public init(
_ defaults: UserDefaults = UserDefaults(suiteName: "foobar")
?? .standard
) {
self.defaults = defaults
}
I know I could in theory just pass the suite name and make UserDefaults computed (btw, is UserDefaults.standard also computed?), however I still don't get why UserDefaults is not sendable despite the docs mentioning its thread safe.
Post
Replies
Boosts
Views
Activity
I've also filed a radar: FB10224177