What is the difference between "-copy" and "-copyWithZone:"?

I know that a copy creates an immutable copy of an object, but I just want to know how copywithzone works and what is the main difference between copy and copywithzone

+6
source share
2 answers

copy simply abbreviated for copyWithZone: using the default zone.

it is rarely what you call copyWithZone: directly, although a definition / implementation is required to accept @protocol NSCopying . therefore, you usually see copyWithZone: only in the implementation of copyWithZone: similarly, you usually avoid the copy implementation, and just let the default implementation of copy through copyWithZone:

+11
source

NSZone is an outdated concept that has nothing to do with iOS. By default, NSObject on NSObject will call -copyWithZone: with the default zone.

+5
source

Source: https://habr.com/ru/post/923344/


All Articles