![](/img/trans.png)
[英]Type 'AnyObject' does not conform to protocol 'Hashable'
[英]'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'CarnivalWheel' to 'Hashable' by implementing 'hash(into:)' instead
似乎無法正確更改哈希(到 :)? 我嘗試的一切只會帶來一個新的錯誤
對此的任何幫助將不勝感激,Swift 5
import UIKit
import TTFortuneWheel
class CarnivalWheel: FortuneWheelSliceProtocol, Codable, Hashable {
static func == (lhs: CarnivalWheel, rhs: CarnivalWheel) -> Bool {
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
}
var hashValue: Int {
return ObjectIdentifier(self).hashValue
}
enum Style: String, Codable, Hashable {
case blue
case purple
case green
case grey
case orange
case yellow
}
var style: Style = .blue
var backgroundColor: UIColor? {
switch style {
case .blue: return TTUtils.uiColor(from: 0xdff9fb)
case .purple: return TTUtils.uiColor(from: 0xa29bfe)
case .green: return TTUtils.uiColor(from: 0x7bed9f)
case . grey: return TTUtils.uiColor(from: 0xdfe4ea)
case .orange: return TTUtils.uiColor(from: 0xffbe76)
case .yellow: return TTUtils.uiColor(from: 0xf6e58d)
}
}
var title: String
var degree: CGFloat = 0.0
init(title: String) {
self.title = title
}
var fontColor: UIColor {
return UIColor.black
}
var offsetFromExterior: CGFloat {
return 10.0
}
var stroke: StrokeInfo? {
return StrokeInfo(color: UIColor.white, width: 1.0)
}
convenience init(title: String, degree: CGFloat) {
self.init(title: title)
self.degree = degree
}
}
func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
}
將增加一致性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.