Dictionary
struct Dictionary<Key, Value> where Key : Hashable
-
Get a value for a given
keyand return as an objectV. If the value is not of the typeVthrows an error.Declaration
Swift
public func fetch<V>(_ key: Key) throws -> VParameters
keyThe key to find in the dictionary.
Return Value
The value associated with
key. -
Get a value for a given
keyand return as an optional objectV. If the value is not of the typeVthrows an error.Declaration
Swift
public func fetchOptional<V>(_ key: Key) throws -> V?Parameters
keyThe key to find in the dictionary.
Return Value
The value associated with
key, ornilif key doesn’t exists in the dictionary. -
Get a value for a given
keyand return as an objectUby transforming it from a typeVto a typeU.Throws
ParserErrorifkeydoesn’t exists in the dictionary or it is not of the typeV, or it couldn’t be transformed to typeU.Declaration
Swift
public func fetch<V, U>(_ key: Key, transformation: (V) throws -> U?) throws -> UParameters
keyThe key to find in the dictionary.
transformationTransformation closure. Transorms from type
VtoU.Return Value
The value associated with
key. -
Get a value for a given
keyand return as an optional objectUby transforming it from a typeVto a typeU.Declaration
Swift
public func fetchOptional<V, U>(_ key: Key, transformation: (V) throws -> U?) throws -> U?Parameters
keyThe key to find in the dictionary.
transformationTransformation closure. Transorms from type
VtoU.Return Value
The value associated with
key. -
Get a value for a given
keyand return as an optional array of objectUby transforming each object of a typeVto a typeU.Declaration
Swift
public func fetchOptionalArray<V, U>(_ key: Key, transformation: (V) throws -> U?) throws -> [U]?Parameters
keyThe key to find in the dictionary.
transformationTransformation closure. Transorms from type
VtoU.Return Value
An optional array of values associated with
key. -
Return first pair (key and value) from dictionary.
Throws
ParserErrorif dictionary is empty.Declaration
Swift
public func fetchFirst() throws -> (key: Key, value: Value)Return Value
First pair (key and value) from dictionary.
-
Return first pair (key and value) from dictionary and transform it to type
T.Throws
ParserErrorif dictionary is empty.Declaration
Swift
public func fetchFirst<T>(transformation: (Key, Value) throws -> T) throws -> TParameters
transformationTransformation closure. Transorms key and value to the type
T.Return Value
First pair (key and value) transformed to type
T.
Dictionary Extension Reference