Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Created January 27, 2018 12:24
Show Gist options
  • Save Marcocanc/6700b87305a903668786fc34298c1914 to your computer and use it in GitHub Desktop.
Save Marcocanc/6700b87305a903668786fc34298c1914 to your computer and use it in GitHub Desktop.
Easily compare two objects by using KeyPath
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