<!--
{
  "availability" : [
    "iOS: 2.0.0 - 11.0.0",
    "iPadOS: 2.0.0 - 11.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSArchiver/encodeClassName(_:intoClassName:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSArchiver(im)encodeClassName:intoClassName:"
  },
  "title" : "encodeClassName(_:intoClassName:)"
}
-->

# encodeClassName(_:intoClassName:)

Encodes a substitute name for the class with a given true name.

```
func encodeClassName(_ trueName: String, intoClassName inArchiveName: String)
```

## Parameters

`trueName`

The real name of a class in the object graph being archived.

`inArchiveName`

The name of the class to use in the archive in place of `trueName`.

## Discussion

Any subsequently encountered objects of class `trueName` are archived as instances of class `inArchiveName`. It is safest not to invoke this method during the archiving process (that is, within an [`encode(with:)`](/documentation/Foundation/NSCoding/encode(with:)) method). Instead, invoke it before [`encodeRootObject(_:)`](/documentation/Foundation/NSArchiver/encodeRootObject(_:)).

---

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)