Rupshikha anand
Rupshikha anand

Reputation: 65

Swift array element map

I have array [[one, two, three, four]] and I want to convert array in [["one", "two"," three", "four"]] without using a loop in Swift 3.

I tried

let myArray = array.map { String($0) }

But this is returning ["[one, two, three, four]"].

Upvotes: 2

Views: 1207

Answers (2)

Santhosh R
Santhosh R

Reputation: 1568

Array([[one, two, three, four]][0].map({String($0)}))

Upvotes: 1

David Berry
David Berry

Reputation: 41226

In your case, you actually have two arrays. You have an array OF arrays of whatever one, etc. are.

Try:

let result = array.map { $0.map { String($0) } }

Upvotes: 3

Related Questions