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

removeFirst()

Removes and returns the first element of the collection. コレクションの最初の要素を削除して返します。

Declaration 宣言

@discardableResult mutating func removeFirst() -> Element

Return Value 戻り値

The removed element. 削除された要素。

Discussion 解説

The collection must not be empty. コレクションは空であってはなりません。


var bugs = ["Aphid", "Bumblebee", "Cicada", "Damselfly", "Earwig"]
bugs.removeFirst()
print(bugs)
// Prints "["Bumblebee", "Cicada", "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 要素の削除