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

# archiver(_:willReplace:with:)

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

## Declaration

```swift
optional func archiver(_ archiver: NSKeyedArchiver, willReplace object: Any?, with newObject: Any?)
```

## Parameters

- `archiver`: The archiver that sent the message.
- `object`: The object being replaced in the archive.
- `newObject`: The object replacing object in the archive.

## Discussion

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

## See Also

### Encoding Data and Objects

- [archiver(_:didEncode:)](foundation/nskeyedarchiverdelegate/archiver(_:didencode:).md)
- [archiverDidFinish(_:)](foundation/nskeyedarchiverdelegate/archiverdidfinish(_:).md)
- [archiver(_:willEncode:)](foundation/nskeyedarchiverdelegate/archiver(_:willencode:).md)
- [archiverWillFinish(_:)](foundation/nskeyedarchiverdelegate/archiverwillfinish(_:).md)
