Legacy Hashing
Prefer using the hash(into:)
function instead of overriding hashValue
- Identifier:
legacy_hashing
- Enabled by default: Yes
- Supports autocorrection: No
- Kind: idiomatic
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
struct Foo: Hashable {
let bar: Int = 10
func hash(into hasher: inout Hasher) {
hasher.combine(bar)
}
}
class Foo: Hashable {
let bar: Int = 10
func hash(into hasher: inout Hasher) {
hasher.combine(bar)
}
}
var hashValue: Int { return 1 }
class Foo: Hashable {
}
class Foo: Hashable {
let bar: String = "Foo"
public var hashValue: String {
return bar
}
}
class Foo: Hashable {
let bar: String = "Foo"
public var hashValue: String {
get { return bar }
set { bar = newValue }
}
}
Triggering Examples
struct Foo: Hashable {
let bar: Int = 10
public ↓var hashValue: Int {
return bar
}
}
class Foo: Hashable {
let bar: Int = 10
public ↓var hashValue: Int {
return bar
}
}