Skip to content

Instance Method

encode(_:)

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.10+ tvOS 9.0+ watchOS 2.0+
Returns a JSON-encoded representation of the value you supply.
func encode<T>(_ value: T) throws -> Data where T : Encodable

Parameters

value

The value to encode.

Return Value

A new Data value containing the encoded JSON data.

Discussion

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.