[swift-users] type casting for Dictionaries keys
Adrian Zubarev
adrian.zubarev at devandartist.com
Thu Mar 23 06:41:29 CDT 2017
It's because AnyHashable is not an existential like Any but a value type (I believe it was a struct) which erases the type restriction from your Hashable type. Simply look up AnyHashable.
--
Adrian Zubarev
Sent with Airmail
Am 23. März 2017 um 12:07:16, Седых Александр via swift-users (swift-users at swift.org(mailto:swift-users at swift.org)) schrieb:
>
> Hello again :)
>
> I have another question.
>
> Why Type casting for Keys of Dictionaries don't work
>
>
> enum Key {
>
>
> case one
>
>
> }
>
>
>
>
>
> let dict: [AnyHashable: Any] = [Key.one : "Hello"]
>
>
> let unwrap: [Key: Any] = dict as! [Key : Any] // error
>
>
>
>
> --
> Седых Александр _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170323/2305372d/attachment.html>
More information about the swift-users
mailing list