【问题标题】:Value of type 'AnyObject' has no member 'hashValue'“AnyObject”类型的值没有成员“hashValue”
【发布时间】:2019-08-14 08:40:11
【问题描述】:

我在我的项目中使用这个LocationPicker,当我构建项目时,库有一个错误说:Value of type 'AnyObject' has no member 'hashValue' 所以我打开了代码,我在这里找到了错误行代码:

open override func isEqual(_ object: Any?) -> Bool {
        guard let object = object else { return false }
        return (object as AnyObject).hashValue == hashValue
    }

我是 swift 的新手,我想也许上面的代码有另一种语法,我正在使用更新版本的 swift 5.0xcode10

我尝试使用 xcode 建议的自动修复功能,但不起作用。

【问题讨论】:

标签: swift xcode anyobject


【解决方案1】:

AnyObject 不遵循 Hashable 协议

open override func isEqual(_ object: Any?) -> Bool {
    guard let object = object else { return false }

    if let object = object as? Hashable {
        return object.hashValue == hashValue
    } else {
        return false
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多