UserDefaults

class UserDefaults : NSObject
  • Mechanica

    Returns true if a key exists. - Note: When a value for a give key is set to nil, the key is automatically removed.

    Declaration

    Swift

    public final func hasKey<T>(_ key: Key<T>) -> Bool
  • Mechanica

    Removes value for key.

    Declaration

    Swift

    public final func removeObject<T>(forKey key: Key<T>)
  • Mechanica

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

    Declaration

    Swift

    public final func object<T>(forKey key: Key<T>) -> T?
  • Mechanica

    Sets the value of the specified default key. - Note: The value parameter can be only property list objects: Data, String, NSNumber, SDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects.

    Declaration

    Swift

    public final func set<T>(object: T?, forKey key: Key<T>)
  • Mechanica

    Returns the String associated with the specified key.

    Declaration

    Swift

    public final func string(forKey key: Key<String>) -> String?
  • Mechanica

    Stores a String (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(string: String?, forKey key: Key<String>)
  • Mechanica

    Returns the NSNumber associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func number(forKey key: Key<NSNumber>) -> NSNumber?
  • Mechanica

    Stores a String (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(number: NSNumber?, forKey key: Key<NSNumber>)
  • Mechanica

    Returns the Array associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func array<T>(forKey key: Key<[T]>) -> [T]?
  • Mechanica

    Stores an Array (or removes the value if nil is passed as the value) for the provided key. - Note: The value parameter can be only property list objects: Data, String, NSNumber, SDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects.

    Declaration

    Swift

    public final func set<T>(array: [T]?, forKey key: Key<[T]>)
  • Mechanica

    Returns the Dictionary associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func dictionary<V: Any>(forKey key: Key<[String: V]>) -> [String: V]?
  • Mechanica

    Stores a Dictionary String:Any for the provided key. - Note: The value parameter can be only property list objects: Data, String, NSNumber, SDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects.

    Declaration

    Swift

    public final func set<V: Any>(dictionary: [String: V]?, forKey key: Key<[String: V]>)
  • Mechanica

    Returns the Date associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func date(forKey key: Key<Date>) -> Date?
  • Mechanica

    Stores a Date value (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(date: Date?, forKey key: Key< Date>)
  • Mechanica

    Returns the Data value associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func data(forKey key: Key<Data>) -> Data?
  • Mechanica

    Stores a Data (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(data: Data?, forKey key: Key< Data>)
  • Mechanica

    Returns the Int value associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func integer(forKey key: Key<Int>) -> Int?
  • Mechanica

    Stores an Int value (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(integer: Int?, forKey key: Key<Int>)
  • Mechanica

    Returns the Double value associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func double(forKey key: Key<Double>) -> Double?
  • Mechanica

    Stores a Double value (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(double: Double?, forKey key: Key<Double>)
  • Mechanica

    Returns the Floating-Point value associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func float(forKey key: Key<Float>) -> Float?
  • Mechanica

    Stores a Floating-Point value (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(float: Float?, forKey key: Key<Float>)
  • Mechanica

    Returns the Bool value associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func bool(forKey key: Key<Bool>) -> Bool?
  • Mechanica

    Stores a Bool value (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(bool: Bool?, forKey key: Key<Bool>)
  • Mechanica

    Returns the URL instance associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func url(forKey key: Key<URL>) -> URL?
  • Mechanica

    Stores an URL instance (or removes the value if nil is passed as the value) for the provided key.

    Declaration

    Swift

    public final func set(url: URL?, forKey key: Key<URL>)
  • Mechanica

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

    Declaration

    Swift

    public final func archivableValue<T: NSCoding>(forKey key: Key<T>) -> T?
  • Mechanica

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

    Declaration

    Swift

    public final func set<T: NSCoding>(archivableValue value: T?, forKey key: Key<T>)
  • 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?

    Parameters

    defaultName

    A key in the current user’s defaults database.

    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?

    Parameters

    defaultName

    A key in the current user’s defaults database.

    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?

    Parameters

    defaultName

    A key in the current user’s defaults database.

    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?

    Parameters

    defaultName

    A key in the current user’s defaults database.

    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 NSCoding associated with the specified key, or nil if the key was not found.

    Declaration

    Swift

    public final func archivableValue<T: NSCoding>(forKey key: String) -> T?
  • Mechanica

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

    Declaration

    Swift

    public final func set<T: NSCoding>(archivableValue value: T?, forKey key: String)