Overridden by subclasses to substitute another object or a copy for itself during distribution encoding.
SDK
- macOS 10.0–10.13Deprecated
Framework
- Foundation
Declaration
- (id)replacementObjectForPortCoder:(NSPort Coder *)coder;
Parameters
aCoder
The port coder encoding the receiver.
Return Value
The object encode instead of the receiver (if different).
Discussion
This method is invoked by NSPort
. NSObject
’s implementation returns an NSDistant
object for the object returned by replacement
, enabling all objects to be distributed by proxy as the default. However, if replacement
returns nil
, NSObject
’s implementation will also return nil
.
Subclasses that want to be passed by copy instead of by reference must override this method and return self
. The following example shows how to support object replacement both by copy and by reference:
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder {
return [encoder isByref] ? [super replacementObjectForPortCoder:encoder] : self;
}