Post

Replies

Boosts

Views

Activity

Reply to UserDefaults not Sendable
Apologies for bumping a long dormant thread but I'm stumped as to why the following allows UserDefaults to be sendable. For context, it's basically a wrapper around UserDefaults, with UD injected in for testability. If we use UD directly, it complains about sendable. If we wrap it in a closure it works, despite in both cases it being the same instance of UD. public static func create(store: UserDefaults = .standard) -> Self { let userDefaults: () -> UserDefaults = { store } return StoreWrapper( boolForKey: { key in guard userDefaults().object(forKey: key) != nil else { return nil } return userDefaults().bool(forKey: key) }, ...
Topic: App & System Services SubTopic: General Tags:
Feb ’26
Reply to UserDefaults not Sendable
Apologies for bumping a long dormant thread but I'm stumped as to why the following allows UserDefaults to be sendable. For context, it's basically a wrapper around UserDefaults, with UD injected in for testability. If we use UD directly, it complains about sendable. If we wrap it in a closure it works, despite in both cases it being the same instance of UD. public static func create(store: UserDefaults = .standard) -> Self { let userDefaults: () -> UserDefaults = { store } return StoreWrapper( boolForKey: { key in guard userDefaults().object(forKey: key) != nil else { return nil } return userDefaults().bool(forKey: key) }, ...
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’26