---
title: "encode(_:to:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/encodableattributedstringkey/encode(_:to:)"
---

# encode(_:to:)

Encodes a value to the provided encoder.

## Declaration

```swift
static func encode(_ value: Self.Value, to encoder: any Encoder) throws
```

## Parameters

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

## Discussion

Discussion This method throws an error if writing to the encoder fails.
