<!--
{
  "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/encodeValue(ofObjCType:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder(im)encodeValueOfObjCType:at:"
  },
  "title" : "encodeValue(ofObjCType:at:)"
}
-->

# encodeValue(ofObjCType:at:)

Encodes a value of the given type at the given address.

```
func encodeValue(ofObjCType type: UnsafePointer<CChar>, at addr: UnsafeRawPointer)
```

## Discussion

Subclasses must override this method, and match it with a subsequent [`decodeValue(ofObjCType:at:)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:)) message.

When calling this method, `valueType` must contain exactly one type code.

For information on creating an Objective-C type code suitable for `valueType`, see [Type Encodings](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100).

### Special Considerations

You should not use this method to encode Objective-C objects. See [`decodeArray(ofObjCType:count:at:)`](/documentation/Foundation/NSCoder/decodeArray(ofObjCType:count:at:)) for more details.

## See Also

[`encodeValuesOfObjCTypes:`](/documentation/Foundation/NSCoder/encodeValuesOfObjCTypes:)

Encodes a series of values of potentially differing Objective-C types.



---

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)