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

# replace(_:with:)

Causes the receiver to treat subsequent requests to encode a given object as though they were requests to encode another given object.

## Declaration

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

## Parameters

- `object`: An object in the object graph being archived.
- `newObject`: The object with which to replace object in the archive.

## Discussion

Discussion Both object and newObject must be valid objects.

## See Also

### Substituting classes or objects

- [classNameEncoded(forTrueClassName:)](foundation/nsarchiver/classnameencoded(fortrueclassname:).md)
- [encodeClassName(_:intoClassName:)](foundation/nsarchiver/encodeclassname(_:intoclassname:).md)
