Contents

moveSubranges(_:to:)

Moves the elements in the given subranges to just before the element at the specified index.

Declaration

@discardableResult mutating func moveSubranges(_ subranges: RangeSet<Self.Index>, to insertionPoint: Self.Index) -> Range<Self.Index>

Parameters

  • subranges:

    The subranges of the elements to move.

  • insertionPoint:

    The index to use as the destination of the elements.

Return Value

The new bounds of the moved elements.

Discussion

This example finds all the uppercase letters in the array and then moves them to between "i" and "j".

var letters = Array("ABCdeFGhijkLMNOp")
let uppercaseRanges = letters.indices(where: { $0.isUppercase })
let rangeOfUppercase = letters.moveSubranges(uppercaseRanges, to: 10)
// String(letters) == "dehijABCFGLMNOkp"
// rangeOfUppercase == 5..<14