Sometimes you want to quickly generate an array in your swift code
without having to manually type in the elements, you can quickly
do that in Swift using the repeating method
Generate 20 Zeros Array
let twentyZeros = Array(repeating: 0, count: 20)
print(twentyZeros)
Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Generate 50 Strings Array
let arrayOfString = Array(repeating: "City", count: 50)
This same method can be applied to any type in swift such as objects,
just provide whatever you want to generate, and specify the count
.
basic