iOS Reference Library Apple Developer
Search

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:.




Last updated: 2009-08-03

Did this document help you? Yes It's good, but... Not helpful...