Reputation: 10786
How do I ensure objects passed to an initializer are copied, rather than only on setting those attributes later?
Using @NSCopying
, Apple says we can achieve copy
-property-like behavior. Per default, the attribute is only assigned though, without calling the setter which does the copying.
This is potentially dangerous as I want to rely on the property being immutable and not being modified without me knowing. (think of getting an NSMutableString
instead of NSString
- copying would give me an immutable instance).
Upvotes: 0
Views: 905
Reputation: 3052
Upvotes: 1