Instance Method インスタンスメソッド

append(_:)

Adds an element to the end of the collection. ある要素をコレクションの終わりに加えます。

Declaration 宣言

mutating func append(_ newElement: UInt8)

Parameters パラメータ

newElement

The element to append to the collection. この要素をコレクションへ追加します。

Discussion 議論

If the collection does not have sufficient capacity for another element, additional storage is allocated before appending newElement. The following example adds a new number to an array of integers: コレクションが別の要素に対して十分な容量を持たないならば、追加のストレージがnewElementを追加する前に割り当てられます。次の例は、ある新しい要素を整数からなる配列へ加えます:


var numbers = [1, 2, 3, 4, 5]
numbers.append(100)


print(numbers)
// Prints "[1, 2, 3, 4, 5, 100]"

Complexity: O(1) on average, over many calls to append(_:) on the same collection. 計算量:同じコレクション上でのappend(_:)への多くの追加に対して、均してO(1)。