UAPreferenceDataStore

@interface UAPreferenceDataStore : NSObject

Wrapper around NSUserDefaults that automatically applies a key prefix to all entries.

  • Checks if the key exists in the preference data store

    Declaration

    Objective-C

    - (BOOL)keyExists:(nonnull NSString *)key;

    Swift

    func keyExists(_ key: String) -> Bool

    Parameters

    key

    The preference key.

    Return Value

    YES if the key exists

  • Returns the object associated with the key.

    Declaration

    Objective-C

    - (nonnull id)objectForKey:(nonnull NSString *)key;

    Swift

    func object(forKey key: String) -> Any

    Parameters

    key

    The preference key.

  • Removes the value of the specified default key.

    Declaration

    Objective-C

    - (void)removeObjectForKey:(nonnull NSString *)key;

    Swift

    func removeObject(forKey key: String)

    Parameters

    key

    The preference key.

  • Returns the string associated with the key.

    Declaration

    Objective-C

    - (nullable NSString *)stringForKey:(nonnull NSString *)key;

    Swift

    func string(forKey key: String) -> String?

    Parameters

    key

    The preference key.

  • Returns the array associated with the key.

    Declaration

    Objective-C

    - (nullable NSArray *)arrayForKey:(nonnull NSString *)key;

    Swift

    func array(forKey key: String) -> [Any]?

    Parameters

    key

    The preference key.

  • Returns the dictionary associated with the key.

    Declaration

    Objective-C

    - (nullable NSDictionary *)dictionaryForKey:(nonnull NSString *)key;

    Swift

    func dictionary(forKey key: String) -> [AnyHashable : Any]?

    Parameters

    key

    The preference key.

  • Returns the data associated with the key.

    Declaration

    Objective-C

    - (nullable NSData *)dataForKey:(nonnull NSString *)key;

    Swift

    func data(forKey key: String) -> Data?

    Parameters

    key

    The preference key.

  • Returns the string array associated with the key.

    Declaration

    Objective-C

    - (nullable NSArray *)stringArrayForKey:(nonnull NSString *)key;

    Swift

    func stringArray(forKey key: String) -> [Any]?

    Parameters

    key

    The preference key.

  • Returns the integer associated with the key.

    Declaration

    Objective-C

    - (NSInteger)integerForKey:(nonnull NSString *)key;

    Swift

    func integer(forKey key: String) -> Int

    Parameters

    key

    The preference key.

  • Returns the float associated with the key.

    Declaration

    Objective-C

    - (float)floatForKey:(nonnull NSString *)key;

    Swift

    func float(forKey key: String) -> Float

    Parameters

    key

    The preference key.

  • Returns the double associated with the key.

    Declaration

    Objective-C

    - (double)doubleForKey:(nonnull NSString *)key;

    Swift

    func double(forKey key: String) -> Double

    Parameters

    key

    The preference key.

  • Returns the double associated with the key. If the key doesn’t exist, return the default.

    Declaration

    Objective-C

    - (double)doubleForKey:(nonnull NSString *)key
              defaultValue:(double)defaultValue;

    Swift

    func double(forKey key: String, defaultValue: Double) -> Double

    Parameters

    key

    The preference key.

    defaultValue

    The value to return if there is no value for the preference key.

  • Returns the BOOL associated with the key.

    Declaration

    Objective-C

    - (BOOL)boolForKey:(nonnull NSString *)key;

    Swift

    func bool(forKey key: String) -> Bool

    Parameters

    key

    The preference key.

  • Returns the BOOL associated with the key. If the key doesn’t exist, return the default

    Declaration

    Objective-C

    - (BOOL)boolForKey:(nonnull NSString *)key defaultValue:(BOOL)defaultValue;

    Swift

    func bool(forKey key: String, defaultValue: Bool) -> Bool

    Parameters

    key

    The preference key.

    defaultValue

    The value to return if there is no value for the preference key.

  • Returns the URL associated with the key.

    Declaration

    Objective-C

    - (nullable NSURL *)URLForKey:(nonnull NSString *)key;

    Swift

    func url(forKey key: String) -> URL?

    Parameters

    key

    The preference key.

  • Sets the value of the specified key.

    Declaration

    Objective-C

    - (void)setInteger:(NSInteger)value forKey:(nonnull NSString *)key;

    Swift

    func setInteger(_ value: Int, forKey key: String)

    Parameters

    value

    The preference value.

    key

    The preference key.

  • Sets the value of the specified key.

    Declaration

    Objective-C

    - (void)setFloat:(float)value forKey:(nonnull NSString *)key;

    Swift

    func setFloat(_ value: Float, forKey key: String)

    Parameters

    value

    The preference value.

    key

    The preference key.

  • Sets the value of the specified key.

    Declaration

    Objective-C

    - (void)setDouble:(double)value forKey:(nonnull NSString *)key;

    Swift

    func setDouble(_ value: Double, forKey key: String)

    Parameters

    value

    The preference value.

    key

    The preference key.

  • Sets the value of the specified key.

    Declaration

    Objective-C

    - (void)setBool:(BOOL)value forKey:(nonnull NSString *)key;

    Swift

    func setBool(_ value: Bool, forKey key: String)

    Parameters

    value

    The preference value.

    key

    The preference key.

  • Sets the value of the specified key.

    Declaration

    Objective-C

    - (void)setURL:(nullable NSURL *)url forKey:(nonnull NSString *)key;

    Swift

    func setURL(_ url: URL?, forKey key: String)

    Parameters

    url

    The preference value.

    key

    The preference key.

  • Sets the value of the specified key.

    Declaration

    Objective-C

    - (void)setObject:(nullable id)value forKey:(nonnull NSString *)key;

    Swift

    func setObject(_ value: Any?, forKey key: String)

    Parameters

    value

    The preference value.

    key

    The preference key.

  • Removes all the keys that start with the data store’s key prefix.

    Declaration

    Objective-C

    - (void)removeAll;

    Swift

    func removeAll()