Putting two generic Arrays into one Swift Dictionary with Generics
<p>I'm trying to put two different generic types into a collection. In this example there are two arrays, one containing <code>Int</code>s and the other <code>String</code>s.</p>

<pre><code>let intArray = Array&lt;Int&gt;()
let stringArray = Array&lt;String&gt;()
let dict = [1:intArray, "one": stringArray]
</code></pre>

<p>The error reads <strong>Type of expression is ambiguous without more context.</strong></p>

<p>So I tried specifying the <code>Dictionary</code>'s type </p>

<pre><code>let dict: [Hashable: Any] = [1:intArray, "one": stringArray]
</code></pre>

<p>This leads to two errors.</p>

<ul>
<li><strong>Using 'Hashable' as a concrete type conforming to protocol 'Hashable' is not supported.</strong></li>
<li><strong>Protocol 'Hashable' can only be used as a generic constraint because it has Self or associated type requirements</strong></li>
</ul>

<p>Adding <code>import Foundation</code> and using <code>NSDictionary</code> as the type works fine.</p>

<pre><code>let dict: NSDictionary = [1:intArray, "one": stringArray]
</code></pre>

<p>But this should be possible in pure Swift too without using Foundation. What is the type the <code>Dictionary</code> has to have?</p>

<p>edit: This apparently has more to do with the type of the keys. They have to be of the same type, not just conform to <code>Hashable</code>.</p>

<pre><code>let dict: [Int:Any] = [1:intArray, 2: stringArray]
</code></pre>

<p>This works. But is it possible to make the type of the value more precise? <code>[Int:Array&lt;Any&gt;]</code> does not work.</p>