Created
January 27, 2018 12:24
-
-
Save Marcocanc/6700b87305a903668786fc34298c1914 to your computer and use it in GitHub Desktop.
Easily compare two objects by using KeyPath
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
extension Equatable { | |
func checkIfEqualTo<T: Equatable>(_ other: Self, byComparing paths: KeyPath<Self,T>...) -> Bool { | |
for keyPath in paths { | |
guard self[keyPath: keyPath] == other[keyPath: keyPath] else { | |
return false | |
} | |
} | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment