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

# replacementObject(for:)

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

```
func replacementObject(for coder: NSCoder) -> Any?
```

## Parameters

`coder`

The coder encoding the receiver.

## Return Value

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

## Discussion

An object might encode itself into an archive, but encode a proxy for itself if it’s being encoded for distribution. This method is invoked by `NSCoder`. `NSObject`’s implementation returns `self`.

---

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)