Return to the Main Index
Return to the Alphabetic Index

Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.


Adopted By: various OpenStep classes

Declared In: Foundation/NSObject.h

Protocol Description

A class that defines an immutable vs. mutable distinction adopts this protocol to allow mutable copies of its instances to be made. A mutable copy of an object is usually a shallow copy (as opposed to the deep copy defined in the NSCopying protocol specification). The original and its copy share references to the same instance variables, so that if a component of the copy is changed, for example, that change is reflected in the original.

A class that doesn't define an immutable vs. mutable distinction but that needs to offer both deep and shallow copying shouldn't adopt this protocol. The NSCopying methods should by default be assumed to produce deep copies; the class can then also implement methods to produce shallow copies.

Contrary to most methods, the returned value is owned by the caller, who is responsible for releasing it.

Making Mutable Copies of Objects

- (id)mutableCopyWithZone:(NSZone *)zone Returns a new instance that's a top level, mutable copy of the receiver. For a collection, objects in the collection are retained. Memory for the new instance is allocated from zone. The returned object is owned by the caller, who is responsible for releasing it.