Immutable dictionary initialization in swift
<p>I would like to create an immutable dictionary from an array of structs.  Is there a way to directly do this in the language?  I know it can be done via a temporary mutable dictionary. </p>

<pre><code>class Foo {
    let key: Int
// ... other stuff
    init(key:Int){ self.key = key }
}

let listOfFoos : [Foo] = []

var dict = [Int:Foo]()
for foo in listOfFoos { dict[foo.key] = foo }
let immutableDict = dict
</code></pre>

<p>or by using NSDictionary if Foo is an object</p>

<pre><code>let immutableDict2 : [Int:Foo] = NSDictionary(objects:listOfFoos, forKeys: listOfFoos.map{$0.key}) as! [Int:Foo]
</code></pre>