Reputation: 2012
Say there's a class A with property p1, and setter for p1 has been overwritten. Now I want to implement NSCopying protocol for class A.
In my understanding since you're "copying" an instance of class A, there's no need to trigger any setter methods in copyWithZone:
method. So copyOfInstance -> _p1 = _p1;
is better than copyOfInstance.p1 = _p1
. Is it right?
Upvotes: 1
Views: 71
Reputation: 535202
Yes. You are forming the new object exactly as if you were implementing an initializer. So the rules are the same. Just as you must not use a setter method in an init...
method, so you must not use a setter in copyWithZone:
.
Upvotes: 2