<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder/encode(_:forKey:)-9imtu",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder(im)encodeSize:forKey:"
  },
  "title" : "encode(_:forKey:)"
}
-->

# encode(_:forKey:)

Encodes a size structure and associates it with the given string key.

```
func encode(_ size: NSSize, forKey key: String)
```

## See Also

[`decodeSize(forKey:)`](/documentation/Foundation/NSCoder/decodeSize(forKey:))

Decodes and returns an NSSize structure that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9imtu).



---

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)