Created
August 2, 2023 16:20
-
-
Save helje5/6827f34e9a68951a850faee94f6c4d8d to your computer and use it in GitHub Desktop.
Compare Any w/ Swift 5.7
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
func isEqual(_ lhs: Any, _ rhs: Any) -> Bool { | |
guard let lhs = lhs as? any Equatable else { return false } | |
func isEqual<T: Equatable>(lhs: T, rhs: Any) -> Bool { | |
guard let rhs = rhs as? T else { return false } | |
return lhs == rhs | |
} | |
return isEqual(lhs: lhs, rhs: rhs) | |
} | |
print("5==5", isEqual(5, 5)) // true | |
print("5==6", isEqual(5, 6)) // false | |
print("'Hello'==6", isEqual("Hello", 6)) // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment