2

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]"].

2

2 Answers 2

3

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) } }
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.