<div dir="ltr">Or an enumeration followed by a forEach.<div>[&quot;John&quot;, &quot;Mike&quot;, &quot;Amy&quot;, Kavin&quot;].enumerate().forEach {</div><div>    dic[$0] = $1</div><div>}</div><div>That said, it requires creating a dictionary var first, not a let. If there was an initialiser for Dictionary which took an Array or EnumerateSequence, that might be useful. I&#39;m not sure how I&#39;d attempt to write such an initialiser though.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 10, 2016 at 7:08 PM, Donnacha Oisín Kidney <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I think that use of map is generally discouraged. forEach would probably be more explicit, or a for-loop.<div><br><div><blockquote type="cite"><div><div class="h5"><div>On 10 Jan 2016, at 18:58, 肇鑫 via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">You can use dictionary in a map. You just ignore the return value of the map.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="georgia, serif">var dic = [Int:String]()</font></div><div class="gmail_default"><font face="georgia, serif">var index = 0</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">[&quot;John&quot;, &quot;Mike&quot;, &quot;Amy&quot;, &quot;Kavin&quot;].map {</font></div><div class="gmail_default"><font face="georgia, serif">    dic.updateValue($0, forKey: index)</font></div><div class="gmail_default"><font face="georgia, serif">    index += 1</font></div><div class="gmail_default"><font face="georgia, serif">}</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">print(dic) // [2: &quot;Amy&quot;, 0: &quot;John&quot;, 1: &quot;Mike&quot;, 3: &quot;Kavin&quot;]</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">zhaoxin</font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 11, 2016 at 1:50 AM, Kenny Leung via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All.<br>
<br>
I find that instead of using map() on arrays, I more often use an operation that returns a dictionary from an array. A common case is fetching an array of data, then creating a local cache of it indexed by ID.<br>
<br>
Is there a name for this operation? Is this something that others would like to see added to the standard library?<br>
<br>
-Kenny<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><br>Owen Zhao<br></div></div></div>
</div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Lo8TP3b1oIn3yQXUt9zA1UCQfR-2BMBCuqnubTuDg47-2B3usexigrc8Iux9vXvgEAL0wRBdvtEFYxIxVfpyrhimQ4cGMsUZ-2B8-2BzVACTkBFoqIlPq4LVSf1ja8P72Sb-2FyyYt9BGH7M4C6MzLueO2GJhnZPKVrov-2Bnlo8QRW-2F1jqAtsX8ozJnv60diTlz-2FdZn7ZRo7T-2FlH8GS9OrtmYfgoyV-2BeWujH-2BMRrf9qDt7r2azAtgA-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
_______________________________________________<span class=""><br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=-2F-2BoYEebT9nJ6Tn1eM4dmwhL8-2BwH5ixcf4jim0iIuN5xY0W7ouOu9HVQQhQeUBIm7Ff0vlJE62NabEh2CJFpVjDiAMCySpKeEnznQbp1IUhSZS0bBHGGQmTHG2yEsYLDy3e35v3AiIK4CRVVKSX36LtRRBaTGjosxI2fqU1ANeI1Kf4CV8ZOB69-2F7RgbxsDmeT7Oguk3uh4IRZLyW5Ff5x2nfeNsVDtFzdFDNiuemqNc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>