---
title: "replacementObject(for:)"
framework: objectivec
role: symbol
role_heading: Instance Method
path: "objectivec/nsobject-swift.class/replacementobject(for:)-2l8ox"
---

# replacementObject(for:)

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

## Declaration

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

## Parameters

- `coder`: The coder encoding the receiver.

## Return Value

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

## Discussion

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.

## See Also

### Archiving

- [awakeAfter(using:)](objectivec/nsobject-swift.class/awakeafter(using:).md)
- [classForArchiver](objectivec/nsobject-swift.class/classforarchiver.md)
- [classForCoder](objectivec/nsobject-swift.class/classforcoder.md)
- [classForKeyedArchiver](objectivec/nsobject-swift.class/classforkeyedarchiver.md)
- [classFallbacksForKeyedArchiver()](objectivec/nsobject-swift.class/classfallbacksforkeyedarchiver().md)
- [classForKeyedUnarchiver()](objectivec/nsobject-swift.class/classforkeyedunarchiver().md)
- [replacementObject(for:)](objectivec/nsobject-swift.class/replacementobject(for:)-8ih2x.md)
- [replacementObject(for:)](objectivec/nsobject-swift.class/replacementobject(for:)-60vwc.md)
- [setVersion(_:)](objectivec/nsobject-swift.class/setversion(_:).md)
- [version()](objectivec/nsobject-swift.class/version().md)
