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

# encodeCInt(_:forKey:)

Encodes a C integer value and associates it with the string key.

```
func encodeCInt(_ value: Int32, forKey key: String)
```

## Discussion

Subclasses must override this method if they perform keyed coding.

## See Also

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

Decodes and returns a 64-bit integer value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

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

Decodes and returns an int value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

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

Decodes and returns a 32-bit integer value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

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

Decodes and returns an NSInteger value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.



---

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)