<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableOrderedSet/insert(_:at:)-7qg51",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableOrderedSet(im)insertObject:atIndex:"
  },
  "title" : "insert(_:at:)"
}
-->

# insert(_:at:)

Inserts the given object at the specified index of the mutable ordered set, if it is not already a member.

```
func insert(_ object: Any, at idx: Int)
```

## Parameters

`object`

The object to insert into the set’s content.

`idx`

The index in the mutable ordered set at which to insert `object`. This value must not be greater than the count of elements in the array.
  
  > Important:
  > Important: Raises an ``doc://com.apple.foundation/documentation/Foundation/NSExceptionName/rangeException`` if `idx` is greater than the number of elements in the mutable ordered set.

## Discussion

If the object is already a member, this method has no effect. If the specified index is already occupied, the objects at that index and beyond are shifted by adding `1` to their indexes to make room for the inserted object.

---

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)