Dictionary
struct Dictionary<Key, Value> : Collection, ExpressibleByDictionaryLiteral where Key : Hashable
-
Encodes the receiver as a URL path encoded
String
.Declaration
Swift
public var urlPathEncoded: String
-
Encodes the receiver as URL path encoded
Data
containing UTF-8 characters.Declaration
Swift
public var urlPathEncodedData: Data
-
Encodes the receiver as a query string encoded
String
.Declaration
Swift
public var urlQueryEncoded: String
-
Encodes the receiver as query string encoded
Data
containing UTF-8 characters.Declaration
Swift
public var urlQueryEncodedData: Data
-
Encodes the receiver as a URL form encoded
String
.Declaration
Swift
public var urlFormEncoded: String
-
Encodes the receiver as URL form encoded
Data
containing UTF-8 characters.Declaration
Swift
public var urlFormEncodedData: Data
-
Encodes the receiver as JSON
Data
.Declaration
Swift
public var jsonEncodedData: Data?
-
Attempts to retrieve a value of type
T
from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value of typeT
associated withkey
.Declaration
Swift
public func requiredValue<T>(_ key: JSONKey) throws -> T
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The dictionary value (of type
T
) associated withkey
. -
Attempts to retrieve a
UUID
from the dictionary using the givenJSONKey
.The dictionary value is expected to be of type
String
, and in a format compatible with theUUID(uuidString:)
initializer.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain aString
value associated withkey
, or if the value is not in a format accepted by theUUID(uuidString:)
initializer.Declaration
Swift
public func requiredUUID(_ key: JSONKey) throws -> UUID
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
UUID
associated withkey
. -
Attempts to retrieve a
Bool
value from the dictionary using the givenJSONKey
.This implementation is intended to be forgiving as far as what constitutes a
Bool
value.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as aBool
.Declaration
Swift
public func requiredBool(_ key: JSONKey) throws -> Bool
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
Bool
value associated withkey
. -
Attempts to retrieve a
Bool
value from the dictionary using the givenJSONKey
.This implementation is intended to be forgiving as far as what constitutes a
Bool
value.Note
This function always returns
nil
whenever theDictionary.Key
generic type is notString
.Declaration
Swift
public func optionalBool(_ key: JSONKey) -> Bool?
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
Bool
value associated withkey
, ornil
if there is no value associated withkey
that can be interpreted as aBool
. -
Attempts to retrieve an
Int
value from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as anInt
.Declaration
Swift
public func requiredInt(_ key: JSONKey) throws -> Int
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
Int
value associated withkey
. -
Attempts to retrieve a
Double
value from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as aDouble
.Declaration
Swift
public func requiredDouble(_ key: JSONKey) throws -> Double
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
Double
value associated withkey
. -
Attempts to retrieve a
JSONArray
value from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as aJSONArray
.Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
JSONArray
value associated withkey
. -
Attempts to retrieve an
Array
value whoseElement
s are of typeT
from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as an array ofT
.Declaration
Swift
public func requiredArrayWithTypecast<T>(_ key: JSONKey) throws -> [T]
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The array of
T
values associated withkey
. -
Attempts to retrieve an array of type
A
elements from the receiver using the specifiedJSONKey
. If such a value exists, the given transform function is applied to each element in the array, yielding a newArray
whoseElement
s are of typeT
. If the transform function fails for any element, an error is thrown.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as an array ofA
. Any error thrown by the transform function will also be rethrown.Declaration
Swift
public func requiredArray<T, A>(_ key: JSONKey, withTransform transform: (A) throws -> T) throws -> [T]
Parameters
key
The key whose associated value is to be retrieved.
transform
The transform function to apply to convert
A
intoT
. The function throws an error when the conversion of a given element fails.Return Value
The array of
T
values. -
Attempts to retrieve an array of type
A
elements from the receiver using the specifiedJSONKey
. If such a value exists, the given transform function is applied to each element in the array, yielding a newArray
whoseElement
s are of typeT
. If the transform function fails for any element, the error is ignored and that element is omitted from the returned array.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as an array ofA
.Declaration
Swift
public func requiredArray<T, A>(_ key: JSONKey, withOptionalTransform transform: (A) -> T?) throws -> [T]
Parameters
key
The key whose associated value is to be retrieved.
transform
The transform function to apply to convert
A
intoT
. The function returnsnil
when the conversion of a given element fails.Return Value
The array of
T
values. -
Attempts to retrieve an array of type
A
elements from the receiver using the specifiedJSONKey
. If such a value exists, the given transform function is applied to each element in the array, yielding a newArray
whoseElement
s are of typeT
. If the transform function fails for any element, an error is thrown.Note
This function always returns
nil
whenever theDictionary.Key
generic type is notString
.Throws
The function rethrows any error thrown by
transform
.Declaration
Swift
public func optionalArray<T, A>(_ key: JSONKey, withTransform transform: (A) throws -> T) throws -> [T]?
Parameters
key
The key whose associated value is to be retrieved.
transform
The transform function to apply to convert
A
intoT
. The function throws an error when the conversion of a given element fails.Return Value
The array of
T
values, ornil
if there was no array ofA
values stored in the receiver forkey
. -
Attempts to retrieve an array of type
A
elements from the receiver using the specifiedJSONKey
. If such a value exists, the given transform function is applied to each element in the array, yielding a newArray
whoseElement
s are of typeT
. If the transform function fails for any element, the error is ignored and that element is omitted from the returned array.Note
This function always returns
nil
whenever theDictionary.Key
generic type is notString
.Declaration
Swift
public func optionalArray<T, A>(_ key: JSONKey, withOptionalTransform transform: ((A) -> T?)) -> [T]?
Parameters
key
The key whose associated value is to be retrieved.
transform
The transform function to apply to convert
A
intoT
. The function returnsnil
when the conversion of a given element fails.Return Value
The array of
T
values, ornil
if there was no array ofA
values stored in the receiver forkey
. -
Attempts to retrieve a
[String]
value from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as a[String]
.Declaration
Swift
public func requiredStringArray(_ key: JSONKey) throws -> [String]
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
[String]
value associated withkey
. -
Attempts to retrieve a
JSONDictionary
value from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as aString
.Declaration
Swift
public func requiredDictionary(_ key: JSONKey) throws -> JSONDictionary
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
String
value associated withkey
. -
Attempts to retrieve a
String
value from the dictionary using the givenJSONKey
.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain a value associated withkey
that can be interpreted as aString
.Declaration
Swift
public func requiredString(_ key: JSONKey) throws -> String
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
String
value associated withkey
. -
Attempts to retrieve a
URL
from the dictionary using the givenJSONKey
.The dictionary value is expected to be of type
String
, and in a format compatible with theURL(string:)
initializer.Note
This function always throws an error whenever the
Dictionary.Key
generic type is notString
.Throws
DataTransactionError.jsonFormatError
if the receiver does not contain aString
value associated withkey
, or if the value is not in a format accepted by theURL(string:)
initializer.Declaration
Swift
public func requiredURL(_ key: JSONKey) throws -> URL
Parameters
key
The key whose associated value is to be retrieved.
Return Value
The
URL
associated withkey
.