---
title: "insert(_:beforeIndex:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/entitycollection/insert(_:beforeindex:)"
---

# insert(_:beforeIndex:)

Adds the specified entity to this collection directly before the entity at the given index. If the entity is already located before the index, the collection will not change.

## Declaration

```swift
mutating func insert(_ entity: Entity, beforeIndex index: Int)
```

## Parameters

- `entity`: The entity to add to the collection.
- `index`: The index of an entity to insert in front of. If endIndex is provided, the entity will be appended.

## Discussion

Discussion note: This operation can invalidate the index order of any extant entities.
