---
title: "encodeConditional(_:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/unkeyedencodingcontainer/encodeconditional(_:)"
---

# encodeConditional(_:)

Encodes a reference to the given object only if it is encoded unconditionally elsewhere in the payload (previously, or in the future).

## Declaration

```swift
mutating func encodeConditional<T>(_ object: T) throws where T : AnyObject, T : Encodable
```

## Parameters

- `object`: The object to encode.

## Discussion

Discussion For encoders which don’t support this feature, the default implementation encodes the given object unconditionally. For formats which don’t support this feature, the default implementation encodes the given object unconditionally. note: EncodingError.invalidValue if the given value is invalid in the current context for this format.
