NSDictionary(UAAdditions)

@interface NSDictionary (UAAdditions)

Convenience methods to parse values out of a dictionary.

  • Parses a number out of the dictionary.

    Declaration

    Objective-C

    - (nullable NSNumber *)numberForKey:(nonnull NSString *)key
                           defaultValue:(nullable NSNumber *)defaultValue;

    Swift

    func number(forKey key: String, defaultValue: NSNumber?) -> NSNumber?

    Parameters

    key

    The key.

    defaultValue

    The default value if the value does not exists or is not a number.

    Return Value

    Either the value if it is a number, otherwise the default value.

  • Parses a string out of the dictionary.

    Declaration

    Objective-C

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

    Swift

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

    Parameters

    key

    The key.

    defaultValue

    The default value if the value does not exists or is not a string.

    Return Value

    Either the value if it is a string, otherwise the default value.

  • Parses a dictionary out of the dictionary.

    Declaration

    Objective-C

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

    Swift

    func forKey(_ key: String, defaultValue: [AnyHashable : Any]?) -> [AnyHashable : Any]?

    Parameters

    key

    The key.

    defaultValue

    The default value if the value does not exists or is not a dictionary.

    Return Value

    Either the value if it is a dictionary, otherwise the default value.

  • Parses a array out of the dictionary.

    Declaration

    Objective-C

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

    Swift

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

    Parameters

    key

    The key.

    defaultValue

    The default value if the value does not exists or is not a array.

    Return Value

    Either the value if it is a array, otherwise the default value.