<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Dictionary/Values-swift.struct/moveSubranges(_:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SMsE13moveSubranges_2toSny5IndexQzGs8RangeSetVyADG_ADtF::SYNTHESIZED::s:SD6ValuesV"
  },
  "title" : "moveSubranges(_:to:)"
}
-->

# moveSubranges(_:to:)

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

```
@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
```

> Complexity: O(*n* log *n*) where *n* is the length of the collection.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)