Instance Method

replacementObjectForPortCoder:

Overridden by subclasses to substitute another object or a copy for itself during distribution encoding.

Declaration

- (id)replacementObjectForPortCoder:(NSPortCoder *)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 NSPortCoder. NSObject’s implementation returns an NSDistantObject object for the object returned by replacementObjectForCoder:, enabling all objects to be distributed by proxy as the default. However, if replacementObjectForCoder: 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;
}

See Also

Archiving

- awakeAfterUsingCoder:

Overridden by subclasses to substitute another object in place of the object that was decoded and subsequently received this message.

classForArchiver

The class to substitute for the receiver's own class during archiving.

classForCoder

Overridden by subclasses to substitute a class other than its own during coding.

classForKeyedArchiver

Subclasses to substitute a new class for instances during keyed archiving.

+ classFallbacksForKeyedArchiver

Overridden to return the names of classes that can be used to decode objects if their class is unavailable.

+ classForKeyedUnarchiver

Overridden by subclasses to substitute a new class during keyed unarchiving.

classForPortCoder

Class to substitute for the receiver in distribution encoding.

Deprecated
- replacementObjectForArchiver:

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

Deprecated
- replacementObjectForCoder:

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

- replacementObjectForKeyedArchiver:

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

+ setVersion:

Sets the receiver's version number.

+ version

Returns the version number assigned to the class.