Skip to content

Type MethodFoundationEssentials

encode(_:to:)

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
Encodes a Swift value to the provided encoder, using a default implementation.
static func encode(_ value: Self.Value, to encoder: any Encoder) throws

Parameters

value

The value to encode.

encoder

The encoder to write data to.

Discussion

The default implementation calls down to the value’s Encodable.encode(to:) method.

This method throws an error if writing the encoder fails.