---
title: "insert(_:at:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutableorderedset/insert(_:at:)-7qg51"
---

# insert(_:at:)

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

## Declaration

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

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.

## See Also

### Adding, Removing, and Reordering Entries

- [add(_:)](foundation/nsmutableorderedset/add(_:).md)
- [add(_:count:)](foundation/nsmutableorderedset/add(_:count:).md)
- [addObjects(from:)](foundation/nsmutableorderedset/addobjects(from:).md)
- [insert(_:at:)](foundation/nsmutableorderedset/insert(_:at:)-3ncnm.md)
- [remove(_:)](foundation/nsmutableorderedset/remove(_:).md)
- [removeObject(at:)](foundation/nsmutableorderedset/removeobject(at:).md)
- [removeObjects(at:)](foundation/nsmutableorderedset/removeobjects(at:).md)
- [removeObjects(in:)](foundation/nsmutableorderedset/removeobjects(in:)-8h2kh.md)
- [removeObjects(in:)](foundation/nsmutableorderedset/removeobjects(in:)-9jkis.md)
- [removeAllObjects()](foundation/nsmutableorderedset/removeallobjects().md)
- [replaceObject(at:with:)](foundation/nsmutableorderedset/replaceobject(at:with:).md)
- [replaceObjects(at:with:)](foundation/nsmutableorderedset/replaceobjects(at:with:).md)
- [replaceObjects(in:with:count:)](foundation/nsmutableorderedset/replaceobjects(in:with:count:).md)
- [setObject(_:at:)](foundation/nsmutableorderedset/setobject(_:at:).md)
- [moveObjects(at:to:)](foundation/nsmutableorderedset/moveobjects(at:to:).md)
