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

removeSubrange(_:)

Removes the elements in the specified subrange from the collection. 指定された下位範囲の中の要素をコレクションから削除します。

Declaration 宣言

mutating func removeSubrange<R>(_ bounds: R) where R : RangeExpression, Int == R.Bound

Parameters パラメータ

bounds

The range of the collection to be removed. The bounds of the range must be valid indices of the collection. 削除されることになるコレクションの範囲。この範囲の境界は、コレクションの有効なインデックスでなければなりません。

Discussion 解説

All the elements following the specified position are moved to close the gap. This example removes three elements from the middle of an array of measurements. 指定された位置に続く要素すべては、隙間を埋めるように移動されます。この例は、測定結果からなる配列の真ん中から3つの要素を削除します。


var measurements = [1.2, 1.5, 2.9, 1.2, 1.5]
measurements.removeSubrange(1..<4)
print(measurements)
// Prints "[1.2, 1.5]"

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 要素の削除