Initializer

init(repeating:count:)

Creates a new string representing the given string repeated the specified number of times.

Declaration

init(repeating repeatedValue: String, count: Int)

Parameters

repeatedValue

The string to repeat.

count

The number of times to repeat repeatedValue in the resulting string.

Discussion

For example, use this initializer to create a string with ten "ab" strings in a row.

let zeroes = String(repeating: "ab", count: 10)
print(zeroes)
// Prints "abababababababababab"

See Also

Creating a String

init()

Creates an empty string.

init(Character)

Creates a string containing the given character.

init<S>(S)

Creates a new string containing the characters in the given sequence.

init<S>(S)

Creates a new instance of a collection containing the elements of a sequence.

init(Substring)

Creates a new string from the given substring.

init(repeating: Character, count: Int)

Creates a string representing the given character repeated the specified number of times.

init(repeating: Character, count: Int)

Creates a new collection containing the specified number of a single, repeated value.