<html><head></head><body>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.<br> <br><div class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <p class="gmail_quote" style="color:#000;">Am 23. März 2017 um 12:07:16, Седых Александр via swift-users (<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>) schrieb:</p> <blockquote type="cite" class="gmail_quote"><span><div><div></div><div>
<title></title>
Hello again :)<br>
<br>
I have another question.<br>
<br>
Why Type casting for Keys of Dictionaries don't work<br>
<br>
<p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">enum</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> Key
{</span></p>
<p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">
<span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">case</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> one</span></p>
<p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">
<span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">}</span></p>
<p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">
</p>
<p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">let</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> dict:
[</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #703daa;">AnyHashable</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">Any</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">] =
[</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">Key</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #31595d;">one</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> : </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #d12f1b;">"Hello"</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">]</span></p>
<p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">let</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> unwrap:
[</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">Key</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">Any</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">]
= </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">dict </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">as</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">!
[</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">Key</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> : </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">Any</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">]
// error</span></p>
<br>
<br>
<br>
--<br>
Седых Александр
_______________________________________________<br>swift-users mailing list<br>swift-users@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-users<br></div></div></span></blockquote></body></html>