---
title: "encodeNil(forKey:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/keyedencodingcontainerprotocol/encodenil(forkey:)"
---

# encodeNil(forKey:)

Encodes a null value for the given key.

## Declaration

```swift
mutating func encodeNil(forKey key: Self.Key) throws
```

## Parameters

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

## Discussion

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