---
title: encodeNil()
framework: swift
role: symbol
role_heading: Instance Method
path: swift/singlevalueencodingcontainer/encodenil()
---

# encodeNil()

Encodes a null value.

## Declaration

```swift
mutating func encodeNil() throws
```

## Discussion

Discussion note: EncodingError.invalidValue if a null value is invalid in the current context for this format. note: May not be called after a previous self.encode(_:) call.
