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

# encode(_:forKey:)

Encodes a point and associates it with the specified key in the receiver’s archive.

```
func encode(_ point: CGPoint, forKey key: String)
```

## Parameters

`point`

The point 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 [`decodeCGPoint(forKey:)`](/documentation/Foundation/NSCoder/decodeCGPoint(forKey:)) method to retrieve the data.

## See Also

[`-  decodeCGPointForKey:`](/documentation/Foundation/NSCoder/decodeCGPoint(forKey:))

Decodes and returns the Core Graphics point 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)