1

I have

    var array = [["Chinese"],["Italian"],["Thai"]]

and I'm looking to set the names of these three array values to label in a table list.

I simply can't set my

cell.namelabel.text = array.string 

or something like that.

Would anyone be able to recommend a solution?

2 Answers 2

4

- A quick and dirty way to get it done is here.....

var array = [["Chinese"],["Italian"],["Thai"]]
cell.namelabel.text = array.string  = array[0][0]

- One can also iterate using for-in over the Array of Arrays (ie. array) here and access them but thats just one way to do it.

- One can also try to fetch all the values in the array to a single dimension array, so the access gets easier if thats the motive of the code.

var array = [["Chinese"],["Italian"],["Thai"]]

 var valArray: [String] = []

 for value in array
 {
     for innerValue in value
     {
        valArray.append(innerValue)
     }
 }

 print(valArray)
Sign up to request clarification or add additional context in comments.

2 Comments

The bottom bit can also be done with let oneD = array.flatMap { $0 }.
@0x7fffffff Good one !!
1

You could try array.description. Not quite sure if that is what you are looking for.

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.