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

# insert(contentsOf:beforeIndex:)

Adds the specified sequence of entities to this collection in order, directly before the entity at the given index.

## Declaration

```swift
mutating func insert<S>(contentsOf sequence: S, beforeIndex index: Int) where S : Sequence, S.Element : Entity
```

## Parameters

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

## Discussion

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