<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">I’m talking about a function that does for Dictionaries what map() does for Arrays: it transforms every key and value in the input Dictionary (through a caller-provided function), producing a new Dictionary.</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">You could use this to take a dictionary [String:String] that maps user IDs to product IDs, and produce a dictionary [User:Product].</span><br style="font-size:12.8px"><span style="font-size:12.8px">Or you could invert a dictionary (swapping keys and values.)</span></blockquote><div><br></div><div>Jens, this is untested outside of the repl, but maybe it will help:</div><div>
<p class="gmail-p1">extension Dictionary {<br>
<span class="gmail-s1"> </span>func dictMap<U, V>(closure: @noescape (k: Key, v: Value) -> (U, V)) -> [U:V] {<br>
<span class="gmail-s1"> </span>var ret = [U:V]()<br>
for (k0, v0) in self {<br>
<span class="gmail-s1"> </span>let (k1, v1) = closure(k: k0, v: v0)<br>
ret[k1] = v1<br>
<span class="gmail-s1"> </span>}<br>
return ret<br>
<span class="gmail-s1"> </span>}<br>
}<br>
let mapped = [1: 1, 2: 2].dictMap() { (k,v) in return (String(k), String(v)) }<br>
print(mapped)</p>// Prints:<br>// ["2": "2", "1": "1"]</div><div><br></div><div>Lou</div></div>