-2

I wanted to know why can't you hold instances of a class in a variables -> why does it have to be a reference. That's a bit problematic because if I want to store a object in a two variables it any changes made to the object will change the values of my variables. Is there a way around it ?

thanks,

Nant
  • 569
  • 2
  • 10
  • 24
  • 4
    "*Is there a way around it*" – Yes, use value types. I would recommend having a read of https://developer.apple.com/swift/blog/?id=10 & https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html#//apple_ref/doc/uid/TP40014097-CH13-ID88. – Hamish Mar 12 '17 at 12:18
  • Uhh... value types? – Sweeper Mar 12 '17 at 13:21

1 Answers1

2

you can use struct instead of class because structures pass by value

Why Choose Struct Over Class?

Community
  • 1
  • 1
Marian
  • 144
  • 2
  • 11