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).

  1. use @nscopying while declaring property.
  2. from within initialiser call self.propertyname = newvalue, setter gets called , copying done.
  3. to know when value being modified outside of class, implement "set" observer (which requires implement well).

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -