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

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -