<!--
{
  "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/NSKeyedArchiver/setClassName(_:for:)-swift.method",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedArchiver(im)setClassName:forClass:"
  },
  "title" : "setClassName(_:for:)"
}
-->

# setClassName(_:for:)

Sets a mapping for this archiver to encode instances of a given class with the provided name, rather than their real name.

```
func setClassName(_ codedName: String?, for cls: AnyClass)
```

## Parameters

`codedName`

The name of the class that the receiver uses uses in place of `cls`.

`cls`

The class for which to set up a translation mapping.

## Discussion

When encoding, the receiver’s translation map overrides any translation that may also be present in the class’s map.

---

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)