---
title: "replace(_:with:maxReplacements:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/rangereplaceablecollection/replace(_:with:maxreplacements:)-5u0yu"
---

# replace(_:with:maxReplacements:)

Replaces all occurrences of a target sequence with a given collection

## Declaration

```swift
mutating func replace<C, Replacement>(_ other: C, with replacement: Replacement, maxReplacements: Int = .max) where C : Collection, Replacement : Collection, Self.Element == C.Element, C.Element == Replacement.Element
```

## Parameters

- `other`: The sequence to replace.
- `replacement`: The new elements to add to the collection.
- `maxReplacements`: A number specifying how many occurrences of other to replace. Default is Int.max.
