<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/KeyedEncodingContainer/encode(_:forKey:)-8yufz",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s30KeyedEncodingContainerProtocolPsE6encode_6forKeyys6Int128V_0G0QztKF::SYNTHESIZED::s:s22KeyedEncodingContainerV"
  },
  "title" : "encode(_:forKey:)"
}
-->

# encode(_:forKey:)

Encodes the given value for the given key.

```
mutating func encode(_ value: Int128, forKey key: Self.Key) throws
```

## Parameters

`value`

The value to encode.

`key`

The key to associate the value with.

## Discussion> throws: `EncodingError.invalidValue` if the given value is invalid in
> the current context for this 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)