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

2

8

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

Freddiefreddy answered 21/8, 2012 at 5:31 Comment(0)
B
14

copy is just short for copyWithZone:, using the default zone.

it's rare that you would call copyWithZone: directly, although defining/implementing it is required in order to adopt @protocol NSCopying. so you would normally see copyWithZone: only within an implementation of copyWithZone:. similarly, you would typically avoid implementing copy, and just let the default implementation of copy call through copyWithZone:.

Bermejo answered 21/8, 2012 at 5:39 Comment(0)
L
5

NSZone is a legacy concept that has no bearing on iOS. By default -copy on an NSObject will call -copyWithZone: with the default zone.

Lionfish answered 21/8, 2012 at 5:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.