<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Jens, I see now. I believe this is talked months ago. There is no directly function at the moment. You can do:</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">var dict1:<span style="font-size:13px;font-family:arial,sans-serif">[String:String] = ...</span></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:13px;font-family:arial,sans-serif">var dict2:</span><span style="font-size:13px;font-family:arial,sans-serif"> </span><span style="font-size:13px;font-family:arial,sans-serif">[User:Product] = [:]</span></div><div class="gmail_default">_ = dict1.map {</div><div class="gmail_default"> ....</div><div class="gmail_default"> dict2.updateValue(value, forKey:key)</div><div class="gmail_default"><br></div><div class="gmail_default"> return nil</div><div class="gmail_default">}</div><div class="gmail_default"><br></div><div class="gmail_default">// use dict2</div><div class="gmail_default"><br></div><div class="gmail_default">It is ugly, but it works. However, some people thought this was not a good use of map. And they make an extension of Dictionary themselves. </div><div class="gmail_default"><br></div><div class="gmail_default">You can search it in [swift-user], [swift-evolution] if you can't find it in [swift-user].</div><div class="gmail_default"><br></div><div class="gmail_default">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 30, 2016 at 5:52 AM, Jens Alfke <span dir="ltr"><<a href="mailto:jens@mooseyard.com" target="_blank">jens@mooseyard.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Aug 29, 2016, at 2:07 PM, Zhao Xin <<a href="mailto:owenzx@gmail.com">owenzx@gmail.com</a>> wrote:<br>
><br>
> I don''t quite understand your question. In Swift, Dictionaries are structs. You can always use `let dict2 = dict1`.<br>
<br>
</span>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.<br>
<br>
You could use this to take a dictionary [String:String] that maps user IDs to product IDs, and produce a dictionary [User:Product].<br>
Or you could invert a dictionary (swapping keys and values.)<br>
<span class="HOEnZb"><font color="#888888"><br>
—Jens</font></span></blockquote></div><br></div>