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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -