NSDictionary(FunkyUtilities)
@interface NSDictionary <__covariant KeyType, __covariant ObjectType>
(FunkyUtilities) @end
This extension provides simple and easy to use functional and general utilities for NSDictionary.
If you need to prefix the extension methods in this category, you should import NSDictionary+FunkyPrefixedUtilities.h
, where every utility method is prefixed with the funky_
keyword for compatiblitiy reasons.
See
Prefixed counterpartNSDictionary(FunkyPrefixedUtilities)
See
Mutable counterpartNSMutableDictionary(FunkyUtilities)
-
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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_map:]
Declaration
Objective-C
- (NSDictionary *)map:(FunkyPair * (^)(KeyType, ObjectType))block;
Swift
func 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.
See
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_nilTolerantMap:]
Declaration
Objective-C
- (NSDictionary *)nilTolerantMap:(FunkyPair * (^)(KeyType, ObjectType))block;
Swift
func 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
Mutable counterpart-[NSMutableDictionary(FunkyUtilities) merge:]
See
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_merged:]
Declaration
Objective-C
- (NSDictionary *)merged:(NSDictionary *)other;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_forEach:]
Declaration
Objective-C
- (void)forEach:(void (^)(KeyType, ObjectType))block;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_invertedObjectsAndKeys:]
Declaration
Objective-C
- (NSDictionary<ObjectType, KeyType> *)invertedObjectsAndKeys;
Swift
func invertedObjectsAndKeys() -> [AnyHashable : Any]!
Return Value
A new NSDictionary with the inverted values and keys
-
Filters the dictionary using the given predicate, keeping the elements that are passing the test.
See
Mutable counterpart-[NSMutableDictionary(FunkyUtilities) filter:]
See
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_filtered:]
Declaration
Objective-C
- (NSDictionary<KeyType, ObjectType> *)filtered:(BOOL (^)(KeyType, ObjectType))block;
Swift
func filtered(_ block: ((Any?, Any?) -> Bool)!) -> [AnyHashable : Any]!
Parameters
block
The predicate used to filter the results.
-
Returns whether the condition matches all elements in the dictionary
See
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_all:]
Declaration
Objective-C
- (BOOL)all:(BOOL (^)(KeyType, ObjectType))block;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_none:]
Declaration
Objective-C
- (BOOL)none:(BOOL (^)(KeyType, ObjectType))block;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_contains:]
Declaration
Objective-C
- (BOOL)contains:(BOOL (^)(KeyType, ObjectType))block;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_count:]
Declaration
Objective-C
- (NSInteger)count:(BOOL (^)(KeyType, ObjectType))block;
Swift
func 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.
See
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_reduce:withInitialValue:]
Declaration
Objective-C
- (id)reduce:(id (^)(id, KeyType, ObjectType))block withInitialValue:(id)start;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_keys:]
Declaration
Objective-C
- (NSSet<KeyType> *)keys:(BOOL (^)(id, id))block;
Swift
func 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
Prefixed counterpart-[NSDictionary(FunkyPrefixedUtilities) funky_values:]
Declaration
Objective-C
- (NSSet<ObjectType> *)values:(BOOL (^)(id, id))block;
Swift
func 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