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 given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value of type T associated with key.

    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 with key.

  • Attempts to retrieve a UUID from the dictionary using the given JSONKey.

    The dictionary value is expected to be of type String, and in a format compatible with the UUID(uuidString:) initializer.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a String value associated with key, or if the value is not in a format accepted by the UUID(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 with key.

  • Attempts to retrieve a Bool value from the dictionary using the given JSONKey.

    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 not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as a Bool.

    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 with key.

  • Attempts to retrieve a Bool value from the dictionary using the given JSONKey.

    This implementation is intended to be forgiving as far as what constitutes a Bool value.

    Note

    This function always returns nil whenever the Dictionary.Key generic type is not String.

    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 with key, or nil if there is no value associated with key that can be interpreted as a Bool.

  • Attempts to retrieve an Int value from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as an Int.

    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 with key.

  • Attempts to retrieve a Double value from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as a Double.

    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 with key.

  • Attempts to retrieve a JSONArray value from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as a JSONArray.

    Declaration

    Swift

    public func requiredArray(_ key: JSONKey)
            throws
            -> JSONArray

    Parameters

    key

    The key whose associated value is to be retrieved.

    Return Value

    The JSONArray value associated with key.

  • Attempts to retrieve an Array value whose Elements are of type T from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as an array of T.

    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 with key.

  • Attempts to retrieve an array of type A elements from the receiver using the specified JSONKey. If such a value exists, the given transform function is applied to each element in the array, yielding a new Array whose Elements are of type T. 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 not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as an array of A. 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 into T. 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 specified JSONKey. If such a value exists, the given transform function is applied to each element in the array, yielding a new Array whose Elements are of type T. 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 not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as an array of A.

    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 into T. The function returns nil 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 specified JSONKey. If such a value exists, the given transform function is applied to each element in the array, yielding a new Array whose Elements are of type T. If the transform function fails for any element, an error is thrown.

    Note

    This function always returns nil whenever the Dictionary.Key generic type is not String.

    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 into T. The function throws an error when the conversion of a given element fails.

    Return Value

    The array of T values, or nil if there was no array of A values stored in the receiver for key.

  • Attempts to retrieve an array of type A elements from the receiver using the specified JSONKey. If such a value exists, the given transform function is applied to each element in the array, yielding a new Array whose Elements are of type T. 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 the Dictionary.Key generic type is not String.

    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 into T. The function returns nil when the conversion of a given element fails.

    Return Value

    The array of T values, or nil if there was no array of A values stored in the receiver for key.

  • Attempts to retrieve a [String] value from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key 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 with key.

  • Attempts to retrieve a JSONDictionary value from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as a String.

    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 with key.

  • Attempts to retrieve a String value from the dictionary using the given JSONKey.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a value associated with key that can be interpreted as a String.

    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 with key.

  • Attempts to retrieve a URL from the dictionary using the given JSONKey.

    The dictionary value is expected to be of type String, and in a format compatible with the URL(string:) initializer.

    Note

    This function always throws an error whenever the Dictionary.Key generic type is not String.

    Throws

    DataTransactionError.jsonFormatError if the receiver does not contain a String value associated with key, or if the value is not in a format accepted by the URL(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 with key.