---
title: "encode(_:forKey:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/keyedencodingcontainerprotocol/encode(_:forkey:)-8xq4c"
---

# encode(_:forKey:)

Encodes the given value for the given key.

## Declaration

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

## Parameters

- `value`: The value to encode.
- `key`: The key to associate the value with.

## Discussion

Discussion note: EncodingError.invalidValue if the given value is invalid in the current context for this format.
