Creates a new collection containing the specified number of a single, repeated value.
Required. Default implementation provided.
SDK
- Xcode 10.0+
Framework
- Swift Standard Library
Declaration
init(repeating repeatedValue: Self.Element, count: Int)
Parameters
repeatedValueThe element to repeat.
countThe number of times to repeat the value passed in the
repeatingparameter.countmust be zero or greater.
Discussion
The following example creates an array initialized with five strings containing the letter Z.
let fiveZs = Array(repeating: "Z", count: 5)
print(fiveZs)
// Prints "["Z", "Z", "Z", "Z", "Z"]"