-
Notifications
You must be signed in to change notification settings - Fork 3
Overview_Classes
Tom Ryan edited this page Jun 2, 2015
·
3 revisions
class TutorialClass {
var firstVariable : Int
init(firstVariable : Int) {
self.firstVariable = firstVariable
}
}
When copying a class, the copy is a reference to the original it was copied from.
var classTest = TutorialClass(firstVariable: 0)
var secondClassTest = classTest
println(classTest.firstVariable) // 0
println(secondClassTest.firstVariable) // 0
secondClassTest.firstVariable = 1
println(classTest.firstVariable) // 1
println(secondClassTest.firstVariable) // 1
- Note that
firstVariable
in bothclassTest
andsecondClassTest
are now both set to 1.