---
title: "replaceObjects(in:withObjectsFrom:range:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutablearray/replaceobjects(in:withobjectsfrom:range:)"
---

# replaceObjects(in:withObjectsFrom:range:)

Replaces the objects in the receiving array specified by one given range with the objects in another array specified by another range.

## Declaration

```swift
func replaceObjects(in range: NSRange, withObjectsFrom otherArray: [Any], range otherRange: NSRange)
```

## Parameters

- `range`: The range of objects to be replaced in (or removed from) the receiving array.
- `otherArray`: The array of objects from which to select replacements for the objects in aRange.
- `otherRange`: The range of objects be selected from otherArray as replacements for the objects in aRange.

## Discussion

Discussion The lengths of aRange and otherRange don’t have to be equal: If aRange is longer than otherRange, the extra objects in the receiving array are removed; if otherRange is longer than aRange, the extra objects from otherArray are inserted into the receiving array.

## See Also

### Related Documentation

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

### Replacing Objects

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