WilliamMass WilliamMass - 6 months ago 12
Swift Question

Append arrays in Swift

I have a question, is it possible to append an array of string in an other array. (in Swift)

var array: [String] = []
var array2: [String] = []

array.append("test")
print(array)
example: ["test", "test", "test", "test"]


How can I append just the string "test", "test", "test", "test" in array2 in ()?

print(array2)
example: [("test", "test", "test", "test")]


In the end I would like to have this as result:

print(array2)

[("test", "test", "test", "test"),("test", "test", "test", "test"), ("test", "test", "test", "test")]

Answer

Do you mean:

let array: [String] = ["test1", "test2", "test3"]
var array2: [String] = ["test4", "test5", "test6"]

array2.appendContentsOf(array)

print(array2)