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
Datacontaining 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
Datacontaining 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
Datacontaining 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
Tfrom the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value of typeTassociated withkey.Declaration
Swift
public func requiredValue<T>(_ key: JSONKey) throws -> TParameters
keyThe key whose associated value is to be retrieved.
Return Value
The dictionary value (of type
T) associated withkey. -
Attempts to retrieve a
UUIDfrom 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.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain aStringvalue associated withkey, or if the value is not in a format accepted by theUUID(uuidString:)initializer.Declaration
Swift
public func requiredUUID(_ key: JSONKey) throws -> UUIDParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
UUIDassociated withkey. -
Attempts to retrieve a
Boolvalue from the dictionary using the givenJSONKey.This implementation is intended to be forgiving as far as what constitutes a
Boolvalue.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as aBool.Declaration
Swift
public func requiredBool(_ key: JSONKey) throws -> BoolParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
Boolvalue associated withkey. -
Attempts to retrieve a
Boolvalue from the dictionary using the givenJSONKey.This implementation is intended to be forgiving as far as what constitutes a
Boolvalue.Note
This function always returns
nilwhenever theDictionary.Keygeneric type is notString.Declaration
Swift
public func optionalBool(_ key: JSONKey) -> Bool?Parameters
keyThe key whose associated value is to be retrieved.
Return Value
The
Boolvalue associated withkey, ornilif there is no value associated withkeythat can be interpreted as aBool. -
Attempts to retrieve an
Intvalue from the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as anInt.Declaration
Swift
public func requiredInt(_ key: JSONKey) throws -> IntParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
Intvalue associated withkey. -
Attempts to retrieve a
Doublevalue from the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as aDouble.Declaration
Swift
public func requiredDouble(_ key: JSONKey) throws -> DoubleParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
Doublevalue associated withkey. -
Attempts to retrieve a
JSONArrayvalue from the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as aJSONArray.Parameters
keyThe key whose associated value is to be retrieved.
Return Value
The
JSONArrayvalue associated withkey. -
Attempts to retrieve an
Arrayvalue whoseElements are of typeTfrom the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as an array ofT.Declaration
Swift
public func requiredArrayWithTypecast<T>(_ key: JSONKey) throws -> [T]Parameters
keyThe key whose associated value is to be retrieved.
Return Value
The array of
Tvalues associated withkey. -
Attempts to retrieve an array of type
Aelements 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 newArraywhoseElements 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.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat 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
keyThe key whose associated value is to be retrieved.
transformThe transform function to apply to convert
AintoT. The function throws an error when the conversion of a given element fails.Return Value
The array of
Tvalues. -
Attempts to retrieve an array of type
Aelements 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 newArraywhoseElements 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.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as an array ofA.Declaration
Swift
public func requiredArray<T, A>(_ key: JSONKey, withOptionalTransform transform: (A) -> T?) throws -> [T]Parameters
keyThe key whose associated value is to be retrieved.
transformThe transform function to apply to convert
AintoT. The function returnsnilwhen the conversion of a given element fails.Return Value
The array of
Tvalues. -
Attempts to retrieve an array of type
Aelements 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 newArraywhoseElements are of typeT. If the transform function fails for any element, an error is thrown.Note
This function always returns
nilwhenever theDictionary.Keygeneric 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
keyThe key whose associated value is to be retrieved.
transformThe transform function to apply to convert
AintoT. The function throws an error when the conversion of a given element fails.Return Value
The array of
Tvalues, ornilif there was no array ofAvalues stored in the receiver forkey. -
Attempts to retrieve an array of type
Aelements 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 newArraywhoseElements 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
nilwhenever theDictionary.Keygeneric type is notString.Declaration
Swift
public func optionalArray<T, A>(_ key: JSONKey, withOptionalTransform transform: ((A) -> T?)) -> [T]?Parameters
keyThe key whose associated value is to be retrieved.
transformThe transform function to apply to convert
AintoT. The function returnsnilwhen the conversion of a given element fails.Return Value
The array of
Tvalues, ornilif there was no array ofAvalues 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.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as a[String].Declaration
Swift
public func requiredStringArray(_ key: JSONKey) throws -> [String]Parameters
keyThe key whose associated value is to be retrieved.
Return Value
The
[String]value associated withkey. -
Attempts to retrieve a
JSONDictionaryvalue from the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as aString.Declaration
Swift
public func requiredDictionary(_ key: JSONKey) throws -> JSONDictionaryParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
Stringvalue associated withkey. -
Attempts to retrieve a
Stringvalue from the dictionary using the givenJSONKey.Note
This function always throws an error whenever the
Dictionary.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain a value associated withkeythat can be interpreted as aString.Declaration
Swift
public func requiredString(_ key: JSONKey) throws -> StringParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
Stringvalue associated withkey. -
Attempts to retrieve a
URLfrom 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.Keygeneric type is notString.Throws
DataTransactionError.jsonFormatErrorif the receiver does not contain aStringvalue associated withkey, or if the value is not in a format accepted by theURL(string:)initializer.Declaration
Swift
public func requiredURL(_ key: JSONKey) throws -> URLParameters
keyThe key whose associated value is to be retrieved.
Return Value
The
URLassociated withkey.
View on GitHub
Dictionary Extension Reference