Value of type 'AnyObject' has no member 'hashValue'

940 Views Asked by At

i am using this LocationPicker in my project and when i build the project the library has an error saying this: Value of type 'AnyObject' has no member 'hashValue' so i opened the code and i found the error line here the code:

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

i am new to swift and i am thinking maybe theres another syntax for the above code i am using a newer version of swift 5.0 and xcode10.

i tried using the autofix feature xcode suggests but doesnt work.

1

There are 1 best solutions below

0
李腾芳 On

AnyObject not follow Hashable protocol

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
    }
}