DictionaryEncoder

open class DictionaryEncoder

DictionaryEncoder facilitates the encoding of Encodable values into a dictionary.

  • Initializes self with default strategies.

    Declaration

    Swift

    public init()
  • Encodes the given top-level value and returns its Dictionary representation.

    Throws

    EncodingError.invalidValue if a non-conforming floating-point value is encountered during encoding, and the encoding strategy is .throw.

    Throws

    An error if any value throws an error during encoding.

    Declaration

    Swift

    open func encode<T>(_ value: T) throws -> [String : Any] where T : Encodable

    Parameters

    value

    The value to encode.

    Return Value

    A new Dictionary value containing the encoded dictionary data.