Generic Instance Method 総称体インスタンスメソッド

append(contentsOf:)

Adds the elements of a sequence to the end of the array. あるシーケンスに属する要素を配列の終わりに加えます。

Declaration 宣言

mutating func append<S>(contentsOf newElements: S) where Element == S.Element, S : Sequence

Parameters パラメータ

newElements

The elements to append to the array. 配列に追加する要素。

Discussion 解説

Use this method to append the elements of a sequence to the end of this array. This example appends the elements of a Range<Int> instance to an array of integers. このメソッドを使うことで、あるシーケンスに属する要素をこの配列の終わりに追加してください。この例は、Range<Int>インスタンスの要素を整数からなる配列に加えます。


var numbers = [1, 2, 3, 4, 5]
numbers.append(contentsOf: 10...15)
print(numbers)
// Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"

Complexity: O(m) on average, where m is the length of newElements, over many calls to append(contentsOf:) on the same array. 計算量:O(m)、ここでmnewElementsの長さで、同じ配列上でのappend(contentsOf:)への多くの呼び出しに対してで。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Combining Arrays 配列を結合する