UserDefaults

class UserDefaults : NSObject
  • Mechanica

    Returns true if key exists.

    Declaration

    Swift

    public final func hasKey(_ key: String) -> Bool
  • Mechanica

    Removes all keys and values from user defaults.

    Note

    This method only removes keys on the receiver UserDefaults object. System-defined keys will still be present afterwards. resetStandardUserDefaults simply resets the in-memory user defaults object.

    Declaration

    Swift

    public final func removeAll()
  • Mechanica

    Declaration

    Swift

    public final func optionalInteger(forKey defaultName: String) -> Int?

    Return Value

    The integer value associated with the specified key. If the specified key does not exist, this method returns nil.

  • Mechanica

    Declaration

    Swift

    public final func optionalFloat(forKey defaultName: String) -> Float?

    Return Value

    The floating-point value associated with the specified key. If the key does not exist, this method returns nil.

  • Mechanica

    Declaration

    Swift

    public final func optionalDouble(forKey defaultName: String) -> Double?

    Return Value

    The double value associated with the specified key. If the specified key does not exist, this method returns nil.

  • Mechanica

    Declaration

    Swift

    public final func optionalBool(forKey defaultName: String) -> Bool?

    Return Value

    The bool value associated with the specified key. If the specified key does not exist, this method returns nil.

  • Mechanica

    Returns the object conformig to Codable associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func codableValue<T: Codable>(forKey defaultName: String) -> T?
  • Mechanica

    Stores an object conformig to Codable (or removes the value if nil is passed as the value) for the provided key.

    Throws

    An error if any value throws an error during encoding.

    Declaration

    Swift

    public final func set<T: Codable>(codableValue value: T?, forKey defaultName: String) throws