Post

Replies

Boosts

Views

Activity

Reply to UserDefaults not Sendable
Similar question - if I wrap UserDefaults in the property wrapper (in my example to provide access to shared app group defaults). @propertyWrapper public struct HMASettingsDefault<Value> { let key: String let defaultValue: Value var container: UserDefaults = UserDefaults.standard public var wrappedValue: Value { get { return container.object(forKey: key) as? Value ?? defaultValue } set { if let optionalValue = newValue as? AnyOptional, optionalValue.isNil { container.removeObject(forKey: key) } else { container.set(newValue, forKey: key) } } } } Xcode will report "is not concurrency-safe because it is non-isolated global shared mutable state" in all places where this wrapper is used e.g. @HMASettingsDefault(key: "fixedAppTimezone", defaultValue: Calendar.current.timeZone.identifier, container: MyAppGroup.defaults) static var userTimezoneId: String What would be the best approach to use (promised) threadsafe objects in property wrappers in Swift6 strict concurrency world?
Jun ’24