Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • result Array from first answer is empty :( Commented Nov 26, 2016 at 13:02
  • I don't think you copied my code right. It produced [[[1, 2], [5, 6]], [[3, 4], [5, 6]]] in my playground. Commented Nov 26, 2016 at 13:02
  • 1
    @AlekSzczęsnowicz you could also use a more short version let newArray = array.map { [$0, [5,6]]} where $0 is an element of array, ie its first element is [1,2] then its second is [3,4]. You don't need to write inner in because the compiler is smart enough to know there is a parameter and also doesn't care of its name. if there were two parameters then you would have $0 & $1. Also the closure is smart enough to know that you are returning something so you also don't need to specify that. Swift is super swift! Commented Nov 26, 2016 at 13:16