Dictionary
struct Dictionary<Key, Value> : Collection, ExpressibleByDictionaryLiteral where Key : Hashable
-
Get value for key with type check, returns default value when key doeas not exist either type check was failed
Declaration
Swift
public func value<T>(_ name: Key, _ defaultValue: T) -> T! where Key: EyrDictionaryKey, T: EyrDictionaryValue
Parameters
name
Key value
defaultValue
Default value
Return Value
Value for the key (or defaultValue)
-
Returns value for key with type check
Declaration
Swift
public func value<T>(_ name: Key) -> T? where Key: EyrDictionaryKey, T: EyrDictionaryValue
Parameters
name
Key value
Return Value
Value for the key (or nil when type check was failed)
-
Calls closure with sub-dictionary for key with type check
Declaration
Swift
public func dictionary(_ name: Key, closure: (_ data: Dictionary) -> Void)
Parameters
name
Key value for dictionary container
closure
Closure to be called if type check successed
-
Calls closure for each element of the array in the dictionary array value
Declaration
Swift
public func array<T>(_ name: Key, closure: (_ data: T) -> Void) where Key: EyrDictionaryKey
Parameters
name
Key value for the array container
closure
Closure to be called if type check successed
-
Converts values of the key to an array
Declaration
Swift
public func array<T>(_ name: Key) -> [T] where Key: EyrDictionaryKey
Parameters
name
Key value
Return Value
Result array
-
Special implementation
value<T>
function for Date classDeclaration
Swift
public func date(_ name: Key, _ defaultValue: Date? = nil) -> Date?
Parameters
name
Key value
defaultValue
Default value
Return Value
Date struct with value of unix timestamp from the key, nil if type check was failed
-
Special implementation
value<T>
function for URL classDeclaration
Swift
public func url(_ name: Key, _ defaultValue: URL? = nil) -> URL?
Parameters
name
Key value
defaultValue
Default value
Return Value
URL with string, nil if type check was failed
-
Maps dictionary values to the another dictionary with same keys, using transform closure for values
Declaration
Swift
public func map(_ transform: (Key, Value) -> Value) -> [Key:Value]
Parameters
f
Transform closure
Return Value
Dictionary with the same keys and transformed values
-
Maps dictionary to the array, using transform function for values. It skips nil results
Declaration
Swift
public func mapSkipNil<V>(_ transform: ((Key, Value)) -> V?) -> [V]
Parameters
transform
Transform closure
Return Value
Array with non-nil results of transform closure
-
Maps dictionary to another dictionary
Declaration
Swift
public func mapSkipNil<K, V>(_ transform: ((Key, Value)) -> (K, V)?) -> [K: V]
Parameters
transform
Transform closure (it mapped source pair of key-value to result pair)
Return Value
Dictionary with transformed pairs key-value from the source, exluding nil transform results
-
Filter the dictionary using closure
Declaration
Swift
public func filter(_ check: (Key, Value) -> Bool) -> [Key:Value]
Parameters
f
<#f description#>
Return Value
<#return value description#>
-
Merge dictionary with another dictionary and returns result. When key values has intersections, values from the source dictionary will override existing values
Declaration
Swift
public func merged(with source: [Key: Value]?) -> [Key: Value]
Parameters
with
Source dictionary
Return Value
New dictionary with self and source elemenct
-
Merge the dictionary with another dictionary. When key values has intersections, values from the source dictionary will override existing values
Declaration
Swift
public mutating func merge(with source: [Key: Value]?)
Parameters
with
Source dictionary
Return Value
New dictionary with self and source elemenct
-
Checks dictionary conformity NSDictionary.write(to:atomically). Calls fatalError() if not
Declaration
Swift
public func check()
-
Stores plist representation of the dictionary to the url
Declaration
Swift
public func write(to url: URL, atomically: Bool = true)
Parameters
url
<#url description#>
atomically
<#atomically description#>
-
Undocumented
Declaration
Swift
mutating func add(other:Dictionary)
-
Returns the value of a random Key-Value pair from the Dictionary
Declaration
Swift
public func random() -> Value?
-
Union of self and the input dictionaries.
Declaration
Swift
public func union(_ dictionaries: Dictionary...) -> Dictionary
-
Checks if a key exists in the dictionary.
Declaration
Swift
public func has(_ key: Key) -> Bool
-
Creates an Array with values generated by running each [key: value] of self through the mapFunction.
Declaration
Swift
public func toArray<V>(_ map: (Key, Value) -> V) -> [V]
-
Creates a Dictionary with the same keys as self and values generated by running each [key: value] of self through the mapFunction.
Declaration
Swift
public func mapValues<V>(_ map: (Key, Value) -> V) -> [Key: V]
-
Creates a Dictionary with the same keys as self and values generated by running each [key: value] of self through the mapFunction discarding nil return values.
Declaration
Swift
public func mapFilterValues<V>(_ map: (Key, Value) -> V?) -> [Key: V]
-
Creates a Dictionary with keys and values generated by running each [key: value] of self through the mapFunction discarding nil return values.
Declaration
Swift
public func mapFilter<K, V>(_ map: (Key, Value) -> (K, V)?) -> [K: V]
-
Creates a Dictionary with keys and values generated by running each [key: value] of self through the mapFunction.
Declaration
Swift
public func map<K, V>(_ map: (Key, Value) -> (K, V)) -> [K: V]
-
Checks if test evaluates true for all the elements in self.
Declaration
Swift
public func testAll(_ test: (Key, Value) -> (Bool)) -> Bool
-
Unserialize JSON string into Dictionary
Declaration
Swift
public static func constructFromJSON (json: String) -> Dictionary?
-
Serialize Dictionary into JSON string
Declaration
Swift
public func formatJSON() -> String?
-
Difference of self and the input dictionaries. Two dictionaries are considered equal if they contain the same [key: value] pairs.
Declaration
Swift
public func difference(_ dictionaries: [Key: Value]...) -> [Key: Value]