var mark1 = 300
var mark2 = 400
var mark3 = 900
}
let marks = studentMarks()
println("Mark1 is \(marks.mark1)")
println("Mark2 is \(marks.mark2)")
println("Mark3 is \(marks.mark3)")
When we run the above program using playground, we get the following result:
Mark1 is 300
Mark2 is 400
Mark3 is 900
Class Identity Operators
Classes in Swift refers multiple constants and variables pointing to a single instance. To
know about the constants and variables pointing to a particular class instance identity
operators are used. Class instances are always passed by reference. In Classes NSString,
NSArray, and NSDictionary instances are always assigned and passed around as a
reference to an existing instance, rather than as a copy.
Identical to Operators Not Identical to Operators
Operator used is (===) Operator used is (!==)
Returns true when two constants or
variables pointing to a same instance
Returns true when two constants or
variables pointing to a different instance
class SampleClass: Equatable {
let myProperty: String
init(s: String) {
myProperty = s
}
}
func ==(lhs: SampleClass, rhs: SampleClass) - > Bool {
return lhs.myProperty == rhs.myProperty
}