Swift equal function dont work -
i want check equality between objects error. error within code.
class test { var key: string init(nameparam: string) { self.key = nameparam } func ==(other: test) -> bool { return other.key == self.key } } var t1 = test(nameparam: "test") var t2 = test(nameparam: "test1") if(t1 == t2) { // error: 'test' not convertible 'mirrordisposition' println("...") }
operators must implemented in global scope, not inside class. should implement equality operator outside of class:
class test {...} func == (lhs: test, rhs: test) -> bool { return lhs.key == rhs.key }
suggested reading: operator functions
Comments
Post a Comment