<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder/encode(_:forKey:)-9d1qy",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder(im)encodeUIOffset:forKey:"
  },
  "title" : "encode(_:forKey:)"
}
-->

# encode(_:forKey:)

Encodes offset data and associates it with the specified key in the coder’s archive.

```
func encode(_ offset: UIOffset, forKey key: String)
```

## Parameters

`offset`

The offset data to encode.

`key`

The key identifying the data.

## Discussion

When decoding the data from the archive, you pass the value in the `key` parameter to the corresponding [`decodeUIOffset(forKey:)`](/documentation/Foundation/NSCoder/decodeUIOffset(forKey:)) method to retrieve the data.

## See Also

[`-  decodeUIOffsetForKey:`](/documentation/Foundation/NSCoder/decodeUIOffset(forKey:))

Decodes and returns the UIKit offset structure associated with the specified key in the coder’s archive.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)