---
title: "insert(_:within:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/rangeset/insert(_:within:)"
---

# insert(_:within:)

Inserts a range that contains only the specified index into the range set.

## Declaration

```swift
@discardableResult mutating func insert<C>(_ index: Bound, within collection: C) -> Bool where Bound == C.Index, C : Collection
```

## Parameters

- `index`: The index to insert into the range set. index must be a valid index of collection that isn’t the collection’s endIndex.
- `collection`: The collection that contains index.

## Return Value

Return Value true if the range set was modified, or false if the given index was already in the range set.

## Discussion

Discussion note: O(n), where n is the number of ranges in the range set.
