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

# setClass(_:forClassName:)

Sets a translation mapping on this unarchiver to decode objects encoded with a given class name as instances of a given class instead.

```
func setClass(_ cls: AnyClass?, forClassName codedName: String)
```

## Parameters

`cls`

The class with which to replace instances of the class named `codedName`.

`codedName`

The ostensible name of a class in an archive.

## Discussion

When decoding, the receiver’s translation map overrides any translation that may also be present in the class’s map (see [`setClass(_:forClassName:)`](/documentation/Foundation/NSKeyedUnarchiver/setClass(_:forClassName:)-swift.type.method)).

---

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)