<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/EntityCollection/insert(contentsOf:beforeIndex:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation16EntityCollectionP6insert10contentsOf11beforeIndexyqd___SitSTRd__AA0C0C7ElementRcd__lF"
  },
  "title" : "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.

```
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> Note: This operation can invalidate the index order of any extant entities.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)