Required Instance Methodswift 6.0.3Swift

decode(_:forKey:)

Decodes a value of the given type for the given key.

func decode<T>(_ type: T.Type, forKey key: Self.Key) throws -> T where T : Decodable

Parameters

type

The type of value to decode.

key

The key that the decoded value is associated with.

Returns

A value of the requested type, if present for the given key and convertible to the requested type.

Throws

DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type.

DecodingError.keyNotFound if self does not have an entry for the given key.

DecodingError.valueNotFound if self has a null entry for the given key.