It's "magic," meaning its behavior (see, for instance, the implementation of its runtime support) is not expressible in Swift itself. It's not "sugar" in the sense of a syntax that could be desugared into less ergonomic Swift: there's nothing you can write in Swift that would reproduce the behavior of AnyHashable
.
The custom subtyping relationship between Optional<T>
and T
, and the covariant generics that standard library collections (Array
, etc.) can use but not others, are other examples of "magic" as it relates to Swift types.