---
title: "encode(with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nscoding/encode(with:)"
---

# encode(with:)

Encodes the receiver using a given archiver.

## Declaration

```swift
func encode(with coder: NSCoder)
```

## Parameters

- `coder`: An archiver object.
