---
title: "encode(_:forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nscoder/encode(_:forkey:)-7oo2n"
---

# encode(_:forKey:)

Encodes directional edge inset data and associates it with the specified key in the coder’s archive.

## Declaration

```swift
func encode(_ insets: NSDirectionalEdgeInsets, forKey key: String)
```

## Parameters

- `insets`: The edge insets data to encode.
- `key`: The key identifying the data.

## Discussion

Discussion When decoding the data from the archive, you pass the value in the key parameter to the corresponding decodeDirectionalEdgeInsets(forKey:) method to retrieve the data.

## See Also

### Encoding Geometry-Based Data

- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-29jyx.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-7z9kc.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-10qhm.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-6wq3n.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-26fxa.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-44zsc.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-9d1qy.md)
