Decoder
public extension Decoder
-
Decode a singular value from the underlying data.
Declaration
Swift
func decodeSingleValue<T>(as type: T.Type = T.self) throws -> T where T : Decodable
-
Decode a value for a given key, specified as a string.
Declaration
Swift
func decode<T>(_ key: String, as type: T.Type = T.self) throws -> T where T : Decodable
-
Decode a value for a given key, specified as a
CodingKey
.Declaration
Swift
func decode<T, K>(_ key: K, as type: T.Type = T.self) throws -> T where T : Decodable, K : CodingKey
-
Decode an optional value for a given key, specified as a string. Throws an error if the specified key exists but is not able to be decoded as the inferred type.
Declaration
Swift
func decodeIfPresent<T>(_ key: String, as type: T.Type = T.self) throws -> T? where T : Decodable
-
Decode an optional value for a given key, specified as a
CodingKey
. Throws an error if the specified key exists but is not able to be decoded as the inferred type.Declaration
Swift
func decodeIfPresent<T: Decodable, K: CodingKey>( _ key: K, as type: T.Type = T.self ) throws -> T?
-
Decode a date from a string for a given key (specified as a string), using a specific formatter. To decode a date using the decoder’s default settings, simply decode it like any other value instead of using this method.
Declaration
Swift
func decode<F>(_ key: String, using formatter: F) throws -> Date where F : AnyDateFormatter
-
Decode a date from a string for a given key (specified as a
CodingKey
), using a specific formatter. To decode a date using the decoder’s default settings, simply decode it like any other value instead of using this method.Declaration
Swift
func decode<K, F>(_ key: K, using formatter: F) throws -> Date where K : CodingKey, F : AnyDateFormatter