<!--
{
  "availability" : [
    "iOS: 2.0.0 - 11.0.0",
    "iPadOS: 2.0.0 - 11.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/replacementObject(for:)-8ih2x",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime",
      "ObjectiveC"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)replacementObjectForArchiver:"
  },
  "title" : "replacementObject(for:)"
}
-->

# replacementObject(for:)

Overridden by subclasses to substitute another object for itself during archiving.

```
func replacementObject(for archiver: NSArchiver) -> Any?
```

## Parameters

`archiver`

The archiver creating an archive.

## Return Value

The object to substitute for the receiver during archiving.

## Discussion

This method is invoked by `NSArchiver`. `NSObject`’s implementation returns the object returned by [`replacementObject(for:)`](/documentation/ObjectiveC/NSObject-swift.class/replacementObject(for:)-2l8ox).

---

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)