<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "os",
  "identifier" : "/documentation/os/OSSignpostIntervalState/encode(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "os"
    ],
    "preciseIdentifier" : "s:2os23OSSignpostIntervalStateC6encode2toys7Encoder_p_tKF"
  },
  "title" : "encode(to:)"
}
-->

# encode(to:)

Encodes the interval state into the provided encoder.

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

## Parameters

`encoder`

The encoder to write data to.

## Discussion

> Important:
> You don’t call this method directly. Instead, the object you’re using to encode the interval state, which must adopt the <doc://com.apple.documentation/documentation/Swift/Encoder> protocol, calls it on your behalf as part of the serialization process.

The method throws an error if the interval state is invalid for the specified encoder’s format.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)