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

removeFirst(_:)

Removes the specified number of elements from the beginning of the collection. 指定された数の要素をコレクションの始まりから削除します。

Declaration 宣言

mutating func removeFirst(_ k: Int)

Parameters パラメータ

k

The number of elements to remove from the collection. k must be greater than or equal to zero and must not exceed the number of elements in the collection. コレクションから削除される要素の数。kは、ゼロより大きいか等しくなければなりません、そしてコレクションの中の要素の数を越えてはいけません。

Discussion 解説


var bugs = ["Aphid", "Bumblebee", "Cicada", "Damselfly", "Earwig"]
bugs.removeFirst(3)
print(bugs)
// Prints "["Damselfly", "Earwig"]"

Calling this method may invalidate any existing indices for use with this collection. このメソッドを呼び出すことは、このコレクションで使うためのあらゆる既存のインデックスを無効にします。

Complexity: O(n), where n is the length of the collection. 計算量:O(n)、ここでnはコレクションの長さです。

See Also 参照

Removing Elements 要素の削除