With Xcode 10, and Swift 4.2 there are additional types that conform to Hashable
as long as their elements also conform to Hashable
(Array
, Dictionary
, etc).
I currently have some code in my project to add Hashable
conformance for Swift 4.1 and below like this:
extension Array: Hashable where Element: Hashable {
public var hashValue: Int {
let prime = 31
var result = 1
for element in self {
result = prime * result + element.hashValue
}
return result
}
}
However, even if I add #if !swift(>=4.2)
around the code I still see the same warning in Xcode.
My question is, how can I keep the conditional conformance to Hashable
for Swift 4.1 and below, but silence the warning for Swift 4.2?