---
title: "encode(to:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/suspendingclock/instant/encode(to:)"
---

# encode(to:)

Encodes this value into the given encoder.

## Declaration

```swift
func encode(to encoder: any Encoder) throws
```

## Parameters

- `encoder`: The encoder to write data to.

## Discussion

Discussion If the value fails to encode anything, encoder will encode an empty keyed container in its place. This function throws an error if any values are invalid for the given encoder’s format.
