× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Error: Immutable value passed on reduce function

Antonio Bello
Jun 12, 2015
<p>You can simply make the <code>dictionary</code> parameter mutable by preceding it with <code>var</code>:</p> <pre><code>var final = array.reduce(initial) { (var dictionary, tuple) in ^^^ </code></pre> <p>Note however that using <code>reduce</code> a new dictionary is created at each iteration, making the algorithm very inefficient. You might want to consider using a <em>traditional</em> <code>foreach</code> loop</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/30760156/Error:%20Immutable%20value%20passed%20on%20reduce%20function/30760304">Stack Overflow</a>.</p>
comments powered by Disqus