iOS Developer Library — Pre-Release

Developer

Foundation Framework Reference NSCopying Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSCopying

The NSCopying protocol declares a method for providing functional copies of an object. The exact meaning of “copy” can vary from class to class, but a copy must be a functionally independent object with values identical to the original at the time the copy was made. A copy produced with NSCopying is implicitly retained by the sender, who is responsible for releasing it. More...

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later.
  • Returns a new instance that’s a copy of the receiver. (required)

    Declaration

    Swift

    func copyWithZone(_ zone: NSZone) -> AnyObject

    Objective-C

    - (id)copyWithZone:(NSZone *)zone

    Parameters

    zone

    The zone identifies an area of memory from which to allocate for the new instance. If zone is NULL, the new instance is allocated from the default zone, which is returned from the function NSDefaultMallocZone.

    Discussion

    The returned object is implicitly retained by the sender, who is responsible for releasing it. The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    – mutableCopyWithZone: (NSMutableCopying protocol)
    – copy (NSObject class)