mardi 5 mai 2015

Xcode 6.3.1 Swift - How to copy array by value

I am trying to copy an array and its values. Why are both arrays referencing the same variable? You can try this in Playground.

var view = UIView()
view.tag = 1

var a = [UIView]()
var b = [UIView]()

a.append(view)

b = a
view.tag = 2

a[0].tag // value is 2
b[0].tag // value is 2?

Aucun commentaire:

Enregistrer un commentaire