func toAH<X>(_ x: X) -> AnyHashable { x as! AnyHashable } let s = "foo" let os = Optional(s) let a1 = toAH(s) let a2 = toAH(os) let d1: [AnyHashable: Int] = [s: 1] let d2: [AnyHashable: Int] = [a1: 1] print(d1[s] ?? 99, d1[os] ?? 99, d1[a1] ?? 99, d1[a2] ?? 99) print(d2[s] ?? 99, d2[os] ?? 99, d2[a1] ?? 99, d2[a2] ?? 99)
(edited)