SettingKey

public class SettingKey<ValueType> : SettingKeys where ValueType : SettingGettable, ValueType : SettingSettable

Template class that supports get/set operations for the template type. Using class here instead of struct due to the lazy initialization of the defaultValue at runtime.

  • Undocumented

    Declaration

    Swift

    typealias ValueType = ValueType
  • There are two types of default values: a constant and a generator. The latter is useful when the value must be determined at runtime.

    See more

    Declaration

    Swift

    enum DefaultValue
  • The unique identifier for this setting key

    Declaration

    Swift

    public let userDefaultsKey: String
  • The default value to use when the setting has not yet been set. We defer the setting in case it is from a generator and the initial value must come from runtime code.

    Declaration

    Swift

    public lazy var defaultValue: ValueType { get set }
  • Define a new setting key.

    Declaration

    Swift

    public init(_ key: String, defaultValue: ValueType)

    Parameters

    key

    the unique identifier to use for this setting

    defaultValue

    the constant default value to use

  • Define a new setting key.

    Declaration

    Swift

    public init(_ key: String, defaultValueGenerator: @escaping () -> ValueType)

    Parameters

    key

    the unique identifier to use for this setting

    defaultValueGenerator

    block to call to generate the default value, with a guarantee that this will only be called at most one time.

  • Obtain a setting value.

    Declaration

    Swift

    public func get(_ source: UserDefaults) -> ValueType

    Parameters

    source

    the setting container to query

    Return Value

    the current setting value

  • Set a setting value.

    Declaration

    Swift

    public func set(_ source: UserDefaults, _ value: ValueType)

    Parameters

    source

    the setting container to modify

    value

    the new setting value