“ Hashable.hashValue”已作为协议要求弃用;通过实现'hashinto :)'来使类型'CarnivalWheel'与'Hashable'一致

问题描述

不能似乎正确地更改了哈希值(into :)?我尝试的一切都会带来新的错误

任何对此的帮助, 斯威夫特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,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))
    }

将增加一致性。