Created
March 15, 2016 19:56
-
-
Save maxcampolo/cc1955fc514aef874069 to your computer and use it in GitHub Desktop.
Implementation of the Equatable protocol in Swift on a custom object.
This file contains 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
public class MyCustomObject: Equatable {} | |
// MARK: Equatable | |
/** | |
Evaluate equality as an identity check on an ObjectIdentifier constructed with an instance of our type. This is a public function in the global scope. | |
*/ | |
public func ==(lhs: MyCustomObject, rhs: MyCustomObject) -> Bool { | |
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs) | |
} | |
MyCustomObject() == MyCustomObject() // false | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment