A type-erased hashable value.
public struct AnyHashable {
public init<H>(_ base: H) where H : Hashable
public var base: Any { get }
public static func == (lhs: AnyHashable, rhs: AnyHashable) -> Bool
}
let descriptions: [AnyHashable: Any] = [
AnyHashable("??"): "emoji",
AnyHashable(42): "an Int",
AnyHashable(Int8(43)): "an Int8",
AnyHashable(Set(["a", "b"])): "a set of strings"
]
public struct Dictionary<Key, Value> where Key : Hashable
Key通常要指定一个确定的类型,如果类型不统一,向上抽象;向上无法解决问题,使用AnyHashable
AnyHashable类型擦除的原因:set和dictory需要指定一个确定的类型
原文:https://www.cnblogs.com/feng9exe/p/10524950.html