< Previous PageNext Page > Hide TOC

Copying

To support copying, you adopt the NSCopying protocol. The protocol has a single method—copyWithZone:—that you must implement to allow your objects to be copied. If your application distinguishes between mutable and immutable versions of an entity, you should adopt NSCopying for the immutable version, and NSMutableCopying for the mutable version (you implement mutableCopyWithZone:). The implementation of the copy method is described in detail in Implementing Object Copy.

A "cheap" way to provide customized copy behavior in some situations is to use key-value coding. You can create a dictionary representation of an object using dictionaryWithValuesForKeys:, create a new uninitialized instance of the same class, then use the dictionary to initialize the new instance with setValuesForKeysWithDictionary:.



< Previous PageNext Page > Hide TOC


© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-02-08)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.