---
title: "replaceObject(at:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutablearray/replaceobject(at:with:)"
---

# replaceObject(at:with:)

Replaces the object at index with anObject.

## Declaration

```swift
func replaceObject(at index: Int, with anObject: Any)
```

## Parameters

- `index`: The index of the object to be replaced. This value must not exceed the bounds of the array. important: Raises an NSRangeException if index is beyond the end of the array.
- `anObject`: The object with which to replace the object at index index in the array. This value must not be nil. important: Raises an NSInvalidArgumentException if anObject is nil.

## See Also

### Related Documentation

- [removeObjects(at:)](foundation/nsmutablearray/removeobjects(at:).md)
- [removeObject(at:)](foundation/nsmutablearray/removeobject(at:).md)
- [insert(_:at:)](foundation/nsmutablearray/insert(_:at:)-5dbx5.md)

### Replacing Objects

- [replaceObjects(at:with:)](foundation/nsmutablearray/replaceobjects(at:with:).md)
- [replaceObjects(in:withObjectsFrom:range:)](foundation/nsmutablearray/replaceobjects(in:withobjectsfrom:range:).md)
- [replaceObjects(in:withObjectsFrom:)](foundation/nsmutablearray/replaceobjects(in:withobjectsfrom:).md)
- [setArray(_:)](foundation/nsmutablearray/setarray(_:).md)
