UserDefaults

public extension UserDefaults
  • SwifterSwift: get object from UserDefaults by using subscript

    Declaration

    Swift

    subscript(key: String) -> Any? { get set }

    Parameters

    key

    key in the current user’s defaults database.

  • SwifterSwift: Float from UserDefaults.

    Declaration

    Swift

    func float(forKey key: String) -> Float?

    Parameters

    forKey

    key to find float for.

    Return Value

    Float object for key (if exists).

  • SwifterSwift: Date from UserDefaults.

    Declaration

    Swift

    func date(forKey key: String) -> Date?

    Parameters

    forKey

    key to find date for.

    Return Value

    Date object for key (if exists).

  • SwifterSwift: Retrieves a Codable object from UserDefaults.

    Declaration

    Swift

    func object<T>(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? where T : Decodable, T : Encodable

    Parameters

    type

    Class that conforms to the Codable protocol.

    key

    Identifier of the object.

    decoder

    Custom JSONDecoder instance. Defaults to JSONDecoder().

    Return Value

    Codable object for key (if exists).

  • SwifterSwift: Allows storing of Codable objects to UserDefaults.

    Declaration

    Swift

    func set<T>(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) where T : Decodable, T : Encodable

    Parameters

    object

    Codable object to store.

    key

    Identifier of the object.

    encoder

    Custom JSONEncoder instance. Defaults to JSONEncoder().