Required Instance Methodswift 6.0.1Swift
decodeIfPresent(_:)
Decodes a value of the given type, if present.
mutating func decodeIfPresent(_ type: Int8.Type) throws -> Int8?
Parameters
- type
The type of value to decode.
Returns
A decoded value of the requested type, or nil
if the value is a null value, or if there are no more elements to decode.
Throws
DecodingError.typeMismatch
if the encountered encoded value is not convertible to the requested type.
This method returns nil
if the container has no elements left to decode, or if the value is null. The difference between these states can be distinguished by checking isAtEnd
.
Other requirements
View members
Hide members
This section is hidden by default because it contains too many (41) members.
Instance members
var codingPath: [any CodingKey]
The path of coding keys taken to get to this point in decoding.
var count: Int?
The number of elements contained within this container.
var currentIndex: Int
The current decoding index of the container (i.e. the index of the next element to be decoded.) Incremented after every successful decode call.
var isAtEnd: Bool
A Boolean value indicating whether there are no more elements left to be decoded in the container.
func decode(String.Type
) throws -> String Decodes a value of the given type.
func decode(Bool.Type
) throws -> Bool Decodes a value of the given type.
func decode(Double.Type
) throws -> Double Decodes a value of the given type.
func decode(Float.Type
) throws -> Float Decodes a value of the given type.
func decode(Int.Type
) throws -> Int Decodes a value of the given type.
func decode(UInt.Type
) throws -> UInt Decodes a value of the given type.
func decode<T>(T.Type
) throws -> T Decodes a value of the given type.
func decode(Int8.Type
) throws -> Int8 Decodes a value of the given type.
func decode(Int16.Type
) throws -> Int16 Decodes a value of the given type.
func decode(Int32.Type
) throws -> Int32 Decodes a value of the given type.
func decode(Int64.Type
) throws -> Int64 Decodes a value of the given type.
func decode(UInt8.Type
) throws -> UInt8 Decodes a value of the given type.
func decode(Int128.Type
) throws -> Int128 Decodes a value of the given type.
func decode(UInt16.Type
) throws -> UInt16 Decodes a value of the given type.
func decode(UInt32.Type
) throws -> UInt32 Decodes a value of the given type.
func decode(UInt64.Type
) throws -> UInt64 Decodes a value of the given type.
func decode(UInt128.Type
) throws -> UInt128 Decodes a value of the given type.
func decodeIfPresent(String.Type
) throws -> String? Decodes a value of the given type, if present.
func decodeIfPresent(Bool.Type
) throws -> Bool? Decodes a value of the given type, if present.
func decodeIfPresent(Double.Type
) throws -> Double? Decodes a value of the given type, if present.
func decodeIfPresent(Float.Type
) throws -> Float? Decodes a value of the given type, if present.
func decodeIfPresent(Int.Type
) throws -> Int? Decodes a value of the given type, if present.
func decodeIfPresent(UInt.Type
) throws -> UInt? Decodes a value of the given type, if present.
func decodeIfPresent<T>(T.Type
) throws -> T? Decodes a value of the given type, if present.
func decodeIfPresent(Int16.Type
) throws -> Int16? Decodes a value of the given type, if present.
func decodeIfPresent(Int32.Type
) throws -> Int32? Decodes a value of the given type, if present.
func decodeIfPresent(Int64.Type
) throws -> Int64? Decodes a value of the given type, if present.
func decodeIfPresent(UInt8.Type
) throws -> UInt8? Decodes a value of the given type, if present.
func decodeIfPresent(Int128.Type
) throws -> Int128? Decodes a value of the given type, if present.
func decodeIfPresent(UInt16.Type
) throws -> UInt16? Decodes a value of the given type, if present.
func decodeIfPresent(UInt32.Type
) throws -> UInt32? Decodes a value of the given type, if present.
func decodeIfPresent(UInt64.Type
) throws -> UInt64? Decodes a value of the given type, if present.
func decodeIfPresent(UInt128.Type
) throws -> UInt128? Decodes a value of the given type, if present.
func decodeNil(
) throws -> Bool Decodes a null value.
func nestedContainer<NestedKey>(keyedBy: NestedKey.Type
) throws -> KeyedDecodingContainer<NestedKey> Decodes a nested container keyed by the given type.
func nestedUnkeyedContainer(
) throws -> any UnkeyedDecodingContainer Decodes an unkeyed nested container.
func superDecoder(
) throws -> any Decoder Decodes a nested container and returns a
Decoder
instance for decodingsuper
from that container.
Citizens in Swift
Default implementations
func decodeIfPresent(String.Type
) throws -> String? func decodeIfPresent(Bool.Type
) throws -> Bool? func decodeIfPresent(Double.Type
) throws -> Double? func decodeIfPresent(Float.Type
) throws -> Float? func decodeIfPresent(Int.Type
) throws -> Int? func decodeIfPresent(UInt.Type
) throws -> UInt? func decodeIfPresent<T>(T.Type
) throws -> T? func decodeIfPresent(Int8.Type
) throws -> Int8? func decodeIfPresent(Int16.Type
) throws -> Int16? func decodeIfPresent(Int32.Type
) throws -> Int32? func decodeIfPresent(Int64.Type
) throws -> Int64? func decodeIfPresent(UInt8.Type
) throws -> UInt8? func decodeIfPresent(Int128.Type
) throws -> Int128? func decodeIfPresent(UInt16.Type
) throws -> UInt16? func decodeIfPresent(UInt32.Type
) throws -> UInt32? func decodeIfPresent(UInt64.Type
) throws -> UInt64? func decodeIfPresent(UInt128.Type
) throws -> UInt128?