<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedArchiverDelegate/archiver(_:willReplace:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSKeyedArchiverDelegate(im)archiver:willReplaceObject:withObject:"
  },
  "title" : "archiver(_:willReplace:with:)"
}
-->

# archiver(_:willReplace:with:)

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

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

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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)