---
title: "replace(_:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsunarchiver/replace(_:with:)"
---

# replace(_:with:)

Causes the receiver to substitute one given object for another whenever the latter is extracted from the archive.

## Declaration

```swift
func replace(_ object: Any, with newObject: Any)
```

## Parameters

- `object`: The archived object to replace.
- `newObject`: The object with which to replace object.

## Discussion

Discussion newObject can be of a different class from object, and the class mappings set by classNameDecoded(forArchiveClassName:) and decodeClassName(_:asClassName:) are ignored.

## See Also

### Substituting classes or objects

- [classNameDecoded(forArchiveClassName:)](foundation/nsunarchiver/classnamedecoded(forarchiveclassname:)-swift.type.method.md)
- [decodeClassName(_:asClassName:)](foundation/nsunarchiver/decodeclassname(_:asclassname:)-swift.type.method.md)
- [classNameDecoded(forArchiveClassName:)](foundation/nsunarchiver/classnamedecoded(forarchiveclassname:)-swift.method.md)
- [decodeClassName(_:asClassName:)](foundation/nsunarchiver/decodeclassname(_:asclassname:)-swift.method.md)
