<!--
{
  "availability" : [
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCharacterEncodingDocumentAttribute",
  "metadataVersion" : "0.1.0",
  "role" : "Global Variable",
  "symbol" : {
    "kind" : "Global Variable",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:@NSCharacterEncodingDocumentAttribute"
  },
  "title" : "NSCharacterEncodingDocumentAttribute"
}
-->

# NSCharacterEncodingDocumentAttribute

The string encoding for the document.

```
extern NSAttributedStringDocumentAttributeKey NSCharacterEncodingDocumentAttribute;
```

## Discussion

The value of this attribute is an <doc://com.apple.documentation/documentation/Foundation/NSNumber> object containing integer specifying <doc://com.apple.documentation/documentation/Foundation/NSStringEncoding> for the file; default for plain text is the default encoding. This key in options can specify the string encoding for reading the data. Upon return, the document attributes can contain the actual encoding used. For writing methods, this value is used for generating the plain text data.

The string constant in macOS 10.3 and earlier is `@"CharacterEncoding"`.

---

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)