Swift copy attribute in initializer -
how ensure objects passed initializer copied, rather on setting attributes later?
using @nscopying
, apple says can achieve copy
-property-like behavior. per default, attribute assigned though, without calling setter copying.
this potentially dangerous want rely on property being immutable , not being modified without me knowing. (think of getting nsmutablestring
instead of nsstring
- copying give me immutable instance).
- use @nscopying while declaring property.
- from within initialiser call self.propertyname = newvalue, setter gets called , copying done.
- to know when value being modified outside of class, implement "set" observer (which requires implement well).
Comments
Post a Comment