---
title: "unarchiver(_:willReplace:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nskeyedunarchiverdelegate/unarchiver(_:willreplace:with:)"
---

# unarchiver(_:willReplace:with:)

Informs the delegate that one object is being substituted for another.

## Declaration

```swift
optional func unarchiver(_ unarchiver: NSKeyedUnarchiver, willReplace object: Any, with newObject: Any)
```

## Parameters

- `unarchiver`: An unarchiver for which the receiver is the delegate.
- `object`: An object in the archive.
- `newObject`: The object with which unarchiver will replace object.

## Discussion

Discussion This method is called even when the delegate itself is doing, or has done, the substitution with unarchiver(_:didDecode:). The delegate may use this method if it is keeping track of the encoded or decoded objects.

## See Also

### Decoding Objects

- [unarchiver(_:cannotDecodeObjectOfClassName:originalClasses:)](foundation/nskeyedunarchiverdelegate/unarchiver(_:cannotdecodeobjectofclassname:originalclasses:).md)
- [unarchiver(_:didDecode:)](foundation/nskeyedunarchiverdelegate/unarchiver(_:diddecode:).md)
