下面的代码显示了警告:
❯ swiftc demo.swift [13:06:57]
Swift.RawRepresentable:2:27: warning: 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'PlaybackSpeed' to 'Hashable' by implementing 'hash(into:)' instead
@inlinable public var hashValue: Int { get }
枚举 PlaybackSpeed 应该具有默认实现的函数resetSettings()
& hash(into:)
,因此不应生成此警告。
我的理解是错误的还是编译器错误?
protocol Settingsable {
func resetSettings()
}
protocol SettingsSelectable: Hashable, Settingsable {
var display: String { get }
}
extension SettingsSelectable {
func hash(into hasher: inout Hasher) {
hasher.combine(display)
}
}
extension SettingsSelectable {
func resetSettings() {
print("These have been reset")
}
}
enum PlaybackSpeed: Int, SettingsSelectable {
case half
case standard
case onePointFive
case double
var display: String {
switch self {
case .half:
return "0.5x"
case .standard:
return "1.0x"
case .onePointFive:
return "1.5x"
case .double:
return "2.0x"
}
}
}