<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableOrderedSet/moveObjects(at:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableOrderedSet(im)moveObjectsAtIndexes:toIndex:"
  },
  "title" : "moveObjects(at:to:)"
}
-->

# moveObjects(at:to:)

Moves the objects at the specified indexes to the new location.

```
func moveObjects(at indexes: IndexSet, to idx: Int)
```

## Parameters

`indexes`

The indexes of the objects to move.

`idx`

The index in the mutable ordered set at which to insert the objects. The objects being moved are first removed from the set, then this index is used to find the location at which to insert the moved objects.

## Discussion

For example, the following code results in the contents of `mySet` being equal to `["a", "c", "b", "d", "e"]:`

```swift
let movedObjectIndexes = NSMutableIndexSet()
movedObjectIndexes.addIndex(1)
movedObjectIndexes.addIndex(3)
 
let mySet = NSMutableOrderedSet(capacity: 5)
mySet.addObject("a")
mySet.addObject("b")
mySet.addObject("c")
mySet.addObject("d")
mySet.addObject("e")
 
mySet.moveObjectsAtIndexes(movedObjectIndexes, toIndex: 2)
```

---

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)