Created
July 2, 2015 18:33
-
-
Save uberbruns/a861104b0d1d148e7d7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class BaseClass : Equatable { | |
var stringValue: String = "" | |
} | |
class SubClass : BaseClass { | |
var intValue: Int = 0 | |
} | |
func ==(lhs: BaseClass, rhs: BaseClass) -> Bool | |
{ | |
if lhs.stringValue == rhs.stringValue { | |
return true | |
} else { | |
return false | |
} | |
} | |
func ==(lhs: SubClass, rhs: SubClass) -> Bool | |
{ | |
if (lhs as BaseClass) == (rhs as BaseClass) && | |
lhs.intValue == rhs.intValue { | |
return true | |
} else { | |
return false | |
} | |
} | |
let a1 = BaseClass() | |
a1.stringValue = "Foo" | |
let a2 = BaseClass() | |
a2.stringValue = "Foo" | |
a1 == a2 | |
let b1 = SubClass() | |
b1.stringValue = "Foo" | |
b1.intValue = 4 | |
let b2 = SubClass() | |
b2.stringValue = "Foo" | |
b2.intValue = 2 | |
b1 == b2 | |
let c1: BaseClass = b1 | |
let c2: BaseClass = b2 | |
c1 == c2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment