How can I flatten an array swiftily in Swift? : <p>I want to turn this:</p>

<pre><code>let x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
</code></pre>

<p>into this:</p>

<pre><code>[1, 2, 3, 4, 5, 6, 7, 8, 9]
</code></pre>

<p>very gracefully.</p>

<p>The most straightforward way, of course, is</p>

<pre><code>var y = [Int]()
x.forEach { y.appendContentsOf($0) }
</code></pre>

<p>But that makes the resulting array mutable, which is unnecessary. I don't like this way.</p>

<p>I tried using <code>reduce</code>:</p>

<pre><code>let y = x.reduce([Int]()) { (array, ints) -&gt; [Int] in
    array.appendContentsOf(ints)
    return array
}
</code></pre>

<p>But the compiler complains that <code>array</code> is immutable, so I can't call the mutating method <code>appendContentsOf</code>. </p>

<p>Hence, I added some stuff:</p>

<pre><code>let y = x.reduce([Int]()) { (array, ints) -&gt; [Int] in
    var newArr = array
    newArr.appendContentsOf(ints)
    return newArr
}
</code></pre>

<p>This is just <em>plain bad</em>. I have an instinct that this is not swifty.</p>

<p>How can I flatten an array more swiftily than the above methods? A one-liner would be good.</p>
