SingleUserDefaultsStore

open class SingleUserDefaultsStore<T> where T : Decodable, T : Encodable

SingleUserDefaultsStore offers a convenient way to store a single Codable object in UserDefaults.

  • Store’s unique identifier.

    Warning: Never use the same identifier for two -or more- different stores.

    Declaration

    Swift

    public let uniqueIdentifier: String
  • JSON encoder. default is JSONEncoder()

    Declaration

    Swift

    open var encoder: JSONEncoder
  • JSON decoder. default is JSONDecoder()

    Declaration

    Swift

    open var decoder: JSONDecoder
  • 1tialize store with given identifier.

    Warning: Never use the same identifier for two -or more- different stores.

    Declaration

    Swift

    required public init?(uniqueIdentifier: String)

    Parameters

    uniqueIdentifier

    store’s unique identifier.

  • Save object to store.

    Throws

    JSON encoding error.

    Declaration

    Swift

    public func save(_ object: T) throws

    Parameters

    object

    object to save.

  • Save optional object (if not nil) to store.

    Throws

    JSON encoding error.

    Declaration

    Swift

    public func save(_ optionalObject: T?) throws

    Parameters

    optionalObject

    optional object to save.

  • Get object from store.

    Declaration

    Swift

    public var object: T? { get }
  • Delete object from store.

    Declaration

    Swift

    public func delete()
  • Check if store has an object.

    Declaration

    Swift

    public var hasObject: Bool { get }