WrappedDefault

@propertyWrapper
public struct WrappedDefault<T> where T : UserDefaultsSerializable

A property wrapper that uses UserDefaults as a backing store, whose wrappedValue is non-optional and registers a non-optional default value.

  • key

    The key for the value in UserDefaults.

    Declaration

    Swift

    public let key: String
  • The value retrieved from UserDefaults.

    Declaration

    Swift

    public var wrappedValue: T { get set }
  • A publisher that delivers updates to subscribers.

    Declaration

    Swift

    public var projectedValue: AnyPublisher<T, Never> { get }
  • Initializes the property wrapper.

    Declaration

    Swift

    public init(wrappedValue: T, key keyName: String, userDefaults: UserDefaults = .standard)

    Parameters

    wrappedValue

    The default value to register for the specified key.

    keyName

    The key for the value in UserDefaults.

    userDefaults

    The UserDefaults backing store. The default value is .standard.