NSDictionary(FunkyPrefixedUtilities)

@interface NSDictionary <__covariant KeyType, __covariant ObjectType>
(FunkyPrefixedUtilities) @end

This extension provides simple and easy to use functional and general utilities for NSDictionary. All the methods in this category are prefixed with the funky_ keyword for compatibility reasons. If you prefer unprefixed utilities, you should import NSDictionary+FunkyUtilities.h.

See

Unprefixed counterpart NSDictionary(FunkyUtilities)

See

Mutable counterpart NSMutableDictionary(FunkyPrefixedUtilities)
  • Returns a new NSDictionary instance with the same amount of elements, where each element is transformed to another by returning a new object in the block parameter.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) map:]

    Declaration

    Objective-C

    - (NSDictionary *)funky_map:(FunkyPair * (^)(KeyType, ObjectType))block;

    Swift

    func funky_map(_ block: Any!) -> [AnyHashable : Any]!

    Parameters

    block

    The transformator code which should return a new value based on the existing one.

    Return Value

    A new NSDictionary instance where each element is formed by the result of the block calls

  • Returns a new NSDictionary instance where each element is transformed to another by returning a new object in the block parameter. It ignores the nil parameters returned from the block.

    Declaration

    Objective-C

    - (NSDictionary *)funky_nilTolerantMap:(FunkyPair * (^)(KeyType,
                                                            ObjectType))block;

    Swift

    func funky_nilTolerantMap(_ block: Any!) -> [AnyHashable : Any]!

    Parameters

    block

    The transformator code which should return a new value based on the existing one.

    Return Value

    A new NSDictionary instance where each element is formed by the result of the block calls

  • Returns a new NSDictionary instance, in which concatenates the two dictionaries by putting the existing elements first, and the elements in the provided dictionary after them.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) merged:]

    Declaration

    Objective-C

    - (NSDictionary *)funky_merged:(NSDictionary *)other;

    Swift

    func funky_merged(_ other: [AnyHashable : Any]!) -> [AnyHashable : Any]!

    Parameters

    other

    The other dictionary to merge with

    Return Value

    A new NSDictionary which contains the elements of both dictionaries (self and the other parameter)

  • Calls every element of the dictionary once.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) forEach:]

    Declaration

    Objective-C

    - (void)funky_forEach:(void (^)(KeyType, ObjectType))block;

    Swift

    func funky_(forEach block: ((Any?, Any?) -> Void)!)

    Parameters

    block

    A block, giving the current item and its key in each iteration.

  • Returns a new NSDictionary instance, in which uses the current values as the dictionary and keys and vice-versa. If multiple values are holding the same key, the result (which key is used) is unpredictable.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) invertedObjectsAndKeys:]

    Declaration

    Objective-C

    - (NSDictionary<ObjectType, KeyType> *)funky_invertedObjectsAndKeys;

    Swift

    func funky_invertedObjectsAndKeys() -> [AnyHashable : Any]!

    Return Value

    A new NSDictionary with the inverted values and keys

  • Returns whether the condition matches all elements in the dictionary

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) all:]

    Declaration

    Objective-C

    - (BOOL)funky_all:(BOOL (^)(KeyType, ObjectType))block;

    Swift

    func funky_all(_ block: ((Any?, Any?) -> Bool)!) -> Bool

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    YES if condition matches all elements, NO otherwise

  • Returns whether the condition matches no elements in the dictionary

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) none:]

    Declaration

    Objective-C

    - (BOOL)funky_none:(BOOL (^)(KeyType, ObjectType))block;

    Swift

    func funky_none(_ block: ((Any?, Any?) -> Bool)!) -> Bool

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    NO if condition matches any of the elements, YES otherwise

  • Returns whether the condition matches at least one element in the dictionary

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) contains:]

    Declaration

    Objective-C

    - (BOOL)funky_contains:(BOOL (^)(KeyType, ObjectType))block;

    Swift

    func funky_contains(_ block: ((Any?, Any?) -> Bool)!) -> Bool

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    YES if condition matches any of the elements, NO otherwise

  • Returns the number of elements the given condition matches in the dictionary, like if you would filter the dictionary.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) count:]

    Declaration

    Objective-C

    - (NSInteger)funky_count:(BOOL (^)(KeyType, ObjectType))block;

    Swift

    func funky_count(_ block: ((Any?, Any?) -> Bool)!) -> Int

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    Number of occasions where the condition matches in the dictionary

  • Produces an aggregated value based on the elements of the dictionary.

    Declaration

    Objective-C

    - (id)funky_reduce:(id (^)(id, KeyType, ObjectType))block
        withInitialValue:(id)start;

    Swift

    func funky_reduce(_ block: ((Any?, Any?, Any?) -> Any?)!, withInitialValue start: Any!) -> Any!

    Parameters

    start

    The value to start with. At first this is going to be the rolling value.

    block

    The computation logic, which takes the rolling value and the current item with its index and aggregates them using some custom logic.

    Return Value

    A custom value which is produced by computing all the elements with a custom logic, returned in block

  • Returns all the keys where the given predicate matches the elements of the dictionary.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) keys:]

    Declaration

    Objective-C

    - (NSSet<KeyType> *)funky_keys:(BOOL (^)(id, id))block;

    Swift

    func funky_keys(_ block: ((Any?, Any?) -> Bool)!) -> Set

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    A list of keys where the condition matches

  • Returns all the values where the given predicate matches the elements of the dictionary.

    See

    Unprefixed counterpart -[NSDictionary(FunkyUtilities) values:]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_values:(BOOL (^)(id, id))block;

    Swift

    func funky_values(_ block: ((Any?, Any?) -> Bool)!) -> Set

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    A list of values where the condition matches