<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/replacementObject(for:)-60vwc",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime",
      "ObjectiveC"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)replacementObjectForKeyedArchiver:"
  },
  "title" : "replacementObject(for:)"
}
-->

# replacementObject(for:)

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

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

## Parameters

`archiver`

A keyed archiver creating an archive.

## Return Value

The object encode instead of the receiver (if different).

## Discussion

This method is called only if no replacement mapping for the object has been set up in the encoder (for example, due to a previous call of [`replacementObject(for:)`](/documentation/ObjectiveC/NSObject-swift.class/replacementObject(for:)-60vwc) to that object).

---

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)