struct Card: CustomStringConvertible {
var identity:Int
var description: String {
return "card:\(identity)"
}
static var numberOfCards = 0
init(identity:Int) {
Card.numberOfCards += 1
self.identity = identity
}
}
var cards = [Card]()
let cardOne = Card(identity: 1)
var cardTwo = cardOne //card:1
Card.numberOfCards // 1
cardTwo.identity = 2 // card:2
Card.numberOfCards // 1
With copy-on-write no new object is created until we mutate the object copied. Why does the value of numberOfCard
remain the same after I changed the value of cardTwo
property?