我的iOS项目一直面临以下问题(这只是一个警告).
"哈沙布尔.hashValue作为协议要求被弃用;通过实现"hash(into:)"将类型"ActiveType"与"Hashable"一致
- Xcode 10.2
- Swift 5
源代码:
public enum ActiveType {
case mention
case hashtag
case url
case custom(pattern: String)
var pattern: String {
switch self {
case .mention: return RegexParser.mentionPattern
case .hashtag: return RegexParser.hashtagPattern
case .url: return RegexParser.urlPattern
case .custom(let regex): return regex
}
}
}
extension ActiveType: Hashable, Equatable {
public var hashValue: Int {
switch self {
case .mention: return -1
case .hashtag: return -2
case .url: return -3
case .custom(let regex): return regex.hashValue
}
}
}
有更好的解决方案吗?警告本身建议我实现‘hash(into:)’,但我不知道如何实现?
参考:ActiveLabel