-3

I'm using a WKInterfacePicker and there is a need of inserting dynamic data into the array of the format [(String, String)]. I can insert data statically into this array like,

var cc:[(String, String)] = [
("Item 1", "Row 1"),
("Item 2", "Row 2")]

Can anyone please help me how to insert data into this dynamically ?

1 Answers1

3
var myArray = [(String, String)]()

for index in 1...20 {
    myArray.append(("Item \(index)", "Row \(index)"))
}

print(myArray) // "[("Item 1", "Row 1"), ("Item 2", "Row 2"), ("Item 3", "Row 3"), ("Item 4", "Row 4"), ("Item 5", "Row 5"), ("Item 6", "Row 6"), ("Item 7", "Row 7"), ("Item 8", "Row 8"), ("Item 9", "Row 9"), ("Item 10", "Row 10"), ("Item 11", "Row 11"), ("Item 12", "Row 12"), ("Item 13", "Row 13"), ("Item 14", "Row 14"), ("Item 15", "Row 15"), ("Item 16", "Row 16"), ("Item 17", "Row 17"), ("Item 18", "Row 18"), ("Item 19", "Row 19"), ("Item 20", "Row 20")]\n"
Roy K
  • 3,319
  • 2
  • 27
  • 43