---
title: "decodeIfPresent(_:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/unkeyeddecodingcontainer/decodeifpresent(_:)-gxli"
---

# decodeIfPresent(_:)

Decodes a value of the given type, if present.

## Declaration

```swift
mutating func decodeIfPresent(_ type: Int128.Type) throws -> Int128?
```

## Parameters

- `type`: The type of value to decode.

## Return Value

Return Value 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.

## Discussion

Discussion 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. note: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type.
