Required Instance Methodswift 6.0.1Swift
decodeIfPresent(_:forKey:)
Decodes a value of the given type for the given key, if present.
func decodeIfPresent(_ type: Int.Type, forKey key: Self.Key) throws -> Int?
Parameters
Returns
A decoded value of the requested type, or nil
if the Decoder
does not have an entry associated with the given key, or if the value is a null value.
Throws
DecodingError.typeMismatch
if the encountered encoded value is not convertible to the requested type.
This method returns nil
if the container does not have a value associated with key
, or if the value is null. The difference between these states can be distinguished with a contains(_:)
call.
Other requirements
View members
Hide members
This section is hidden by default because it contains too many (42) members.
Type members
Instance members
var allKeys: [Self.Key]
All the keys the
Decoder
has for this container.var codingPath: [any CodingKey]
The path of coding keys taken to get to this point in decoding.
func contains(Self.Key
) -> Bool Returns a Boolean value indicating whether the decoder contains a value associated with the given key.
func decode(String.Type, forKey: Self.Key
) throws -> String Decodes a value of the given type for the given key.
func decode(Bool.Type, forKey: Self.Key
) throws -> Bool Decodes a value of the given type for the given key.
func decode(Double.Type, forKey: Self.Key
) throws -> Double Decodes a value of the given type for the given key.
func decode(Float.Type, forKey: Self.Key
) throws -> Float Decodes a value of the given type for the given key.
func decode(Int.Type, forKey: Self.Key
) throws -> Int Decodes a value of the given type for the given key.
func decode(UInt.Type, forKey: Self.Key
) throws -> UInt Decodes a value of the given type for the given key.
func decode<T>(T.Type, forKey: Self.Key
) throws -> T Decodes a value of the given type for the given key.
func decode(Int8.Type, forKey: Self.Key
) throws -> Int8 Decodes a value of the given type for the given key.
func decode(Int16.Type, forKey: Self.Key
) throws -> Int16 Decodes a value of the given type for the given key.
func decode(Int32.Type, forKey: Self.Key
) throws -> Int32 Decodes a value of the given type for the given key.
func decode(Int64.Type, forKey: Self.Key
) throws -> Int64 Decodes a value of the given type for the given key.
func decode(UInt8.Type, forKey: Self.Key
) throws -> UInt8 Decodes a value of the given type for the given key.
func decode(Int128.Type, forKey: Self.Key
) throws -> Int128 Decodes a value of the given type for the given key.
func decode(UInt16.Type, forKey: Self.Key
) throws -> UInt16 Decodes a value of the given type for the given key.
func decode(UInt32.Type, forKey: Self.Key
) throws -> UInt32 Decodes a value of the given type for the given key.
func decode(UInt64.Type, forKey: Self.Key
) throws -> UInt64 Decodes a value of the given type for the given key.
func decode(UInt128.Type, forKey: Self.Key
) throws -> UInt128 Decodes a value of the given type for the given key.
func decodeIfPresent(String.Type, forKey: Self.Key
) throws -> String? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Bool.Type, forKey: Self.Key
) throws -> Bool? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Double.Type, forKey: Self.Key
) throws -> Double? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Float.Type, forKey: Self.Key
) throws -> Float? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(UInt.Type, forKey: Self.Key
) throws -> UInt? Decodes a value of the given type for the given key, if present.
func decodeIfPresent<T>(T.Type, forKey: Self.Key
) throws -> T? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Int8.Type, forKey: Self.Key
) throws -> Int8? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Int16.Type, forKey: Self.Key
) throws -> Int16? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Int32.Type, forKey: Self.Key
) throws -> Int32? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Int64.Type, forKey: Self.Key
) throws -> Int64? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(UInt8.Type, forKey: Self.Key
) throws -> UInt8? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(Int128.Type, forKey: Self.Key
) throws -> Int128? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(UInt16.Type, forKey: Self.Key
) throws -> UInt16? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(UInt32.Type, forKey: Self.Key
) throws -> UInt32? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(UInt64.Type, forKey: Self.Key
) throws -> UInt64? Decodes a value of the given type for the given key, if present.
func decodeIfPresent(UInt128.Type, forKey: Self.Key
) throws -> UInt128? Decodes a value of the given type for the given key, if present.
func decodeNil(forKey: Self.Key
) throws -> Bool Decodes a null value for the given key.
func nestedContainer<NestedKey>(keyedBy: NestedKey.Type, forKey: Self.Key
) throws -> KeyedDecodingContainer<NestedKey> Returns the data stored for the given key as represented in a container keyed by the given key type.
func nestedUnkeyedContainer(forKey: Self.Key
) throws -> any UnkeyedDecodingContainer Returns the data stored for the given key as represented in an unkeyed container.
func superDecoder(
) throws -> any Decoder Returns a
Decoder
instance for decodingsuper
from the container associated with the defaultsuper
key.func superDecoder(forKey: Self.Key
) throws -> any Decoder Returns a
Decoder
instance for decodingsuper
from the container associated with the given key.
Citizens in Swift
Default implementations
func decodeIfPresent(String.Type, forKey: Self.Key
) throws -> String? func decodeIfPresent(Bool.Type, forKey: Self.Key
) throws -> Bool? func decodeIfPresent(Double.Type, forKey: Self.Key
) throws -> Double? func decodeIfPresent(Float.Type, forKey: Self.Key
) throws -> Float? func decodeIfPresent(Int.Type, forKey: Self.Key
) throws -> Int? func decodeIfPresent(UInt.Type, forKey: Self.Key
) throws -> UInt? func decodeIfPresent<T>(T.Type, forKey: Self.Key
) throws -> T? func decodeIfPresent(Int8.Type, forKey: Self.Key
) throws -> Int8? func decodeIfPresent(Int16.Type, forKey: Self.Key
) throws -> Int16? func decodeIfPresent(Int32.Type, forKey: Self.Key
) throws -> Int32? func decodeIfPresent(Int64.Type, forKey: Self.Key
) throws -> Int64? func decodeIfPresent(UInt8.Type, forKey: Self.Key
) throws -> UInt8? func decodeIfPresent(Int128.Type, forKey: Self.Key
) throws -> Int128? func decodeIfPresent(UInt16.Type, forKey: Self.Key
) throws -> UInt16? func decodeIfPresent(UInt32.Type, forKey: Self.Key
) throws -> UInt32? func decodeIfPresent(UInt64.Type, forKey: Self.Key
) throws -> UInt64? func decodeIfPresent(UInt128.Type, forKey: Self.Key
) throws -> UInt128?