I\'m learning Swift and found one wonderful tutorial where explained how to create card game. Point is that we use 14 cards with card images and image files are named ca
If I understand the answer correctly, this is the solution:
var cardNamesArray: [String] = []
for i in 0...13 {
cardNamesArray.append("card\(i)")
}
You need to initialise the array once in your program (before filling it), then fill it in for loop.
You also can init your array this way:
var cardNamesArray = [String](count: 14, repeatedValue: "")
This will allocate memory for 14 items of the array, which is better than calling .append() many times.
var cardNamesArray = [String](count: 14, repeatedValue: "")
for i in 0...13 {
cardNamesArray[i] = "card\(i)"
}