Initializer

init(repeating:count:)

Creates a new array containing the specified number of a single, repeated value. 指定された数の、ある単一の値の繰り返しを含んでいる新しい配列を作成します。

Declaration 宣言

init(repeating repeatedValue: Element, count: Int)

Parameters パラメータ

repeatedValue

The element to repeat. 繰り返される要素。

count

The number of times to repeat the value passed in the repeating parameter. count must be zero or greater. repeatingパラメータで渡された値を繰り返す回数。countは、ゼロまたはより大きくなければなりません。

Discussion 解説

Here’s an example of creating an array initialized with five strings containing the letter Z. ここに、字Zを含んでいる5つの文字列で初期化される配列を作成する例があります。


let fiveZs = Array(repeating: "Z", count: 5)
print(fiveZs)
// Prints "["Z", "Z", "Z", "Z", "Z"]"

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Creating an Array 配列の作成