---
title: "setClassName(_:for:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nskeyedarchiver/setclassname(_:for:)-swift.method"
---

# setClassName(_:for:)

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

## Declaration

```swift
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

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

## See Also

### Managing Classes and Class Names

- [setClassName(_:for:)](foundation/nskeyedarchiver/setclassname(_:for:)-swift.type.method.md)
- [className(for:)](foundation/nskeyedarchiver/classname(for:)-swift.type.method.md)
- [className(for:)](foundation/nskeyedarchiver/classname(for:)-swift.method.md)
