Instance Method

encode(to:)

Encodes the contents of this dictionary into the given encoder.

Declaration

func encode(to encoder: Encoder) throws
Available when Key conforms to Encodable and Value conforms to Encodable.

Parameters

encoder

The encoder to write data to.

Discussion

If the dictionary uses String or Int keys, the contents are encoded in a keyed container. Otherwise, the contents are encoded as alternating key-value pairs in an unkeyed container.

This function throws an error if any values are invalid for the given encoder’s format.

Relationships

From Protocol

See Also

Encoding and Decoding

init(from: Decoder)

Creates a new dictionary by decoding from the given decoder.