<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation16EntityCollectionP"
  },
  "title" : "EntityCollection"
}
-->

# EntityCollection

An ordered, mutable collection of entities.

```
protocol EntityCollection : Collection where Self.Element == Entity, Self.Index == Int
```

## Topics

### Instance Methods

[`func append(Entity)`](/documentation/RealityKit/EntityCollection/append(_:))

Adds the specified entity to the end of this collection.

[`func append<S>(contentsOf: S)`](/documentation/RealityKit/EntityCollection/append(contentsOf:))

Adds the specified sequence of entities to the end of this collection,
in order.

[`func insert(Entity, beforeIndex: Int)`](/documentation/RealityKit/EntityCollection/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.

[`func insert<S>(contentsOf: S, beforeIndex: Int)`](/documentation/RealityKit/EntityCollection/insert(contentsOf:beforeIndex:))

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

[`func remove(Entity)`](/documentation/RealityKit/EntityCollection/remove(_:))

Removes the entity from the collection.

[`func remove(at: Int)`](/documentation/RealityKit/EntityCollection/remove(at:))

Removes the entity at the given index from this collection.

[`func removeAll()`](/documentation/RealityKit/EntityCollection/removeAll())

Removes all entities from this collection.

[`func removeAll(where: (Entity) throws -> Bool) rethrows`](/documentation/RealityKit/EntityCollection/removeAll(where:))

Removes all entities from this collection that satisfy the given predicate.

[`func replaceAll<S>(S)`](/documentation/RealityKit/EntityCollection/replaceAll(_:))

Replaces all entities in this collection with those from the given
sequence.

## Relationships

### Inherits From

[`Sequence`](/documentation/Swift/Sequence)

[`Collection`](/documentation/Swift/Collection)

### Conforming Types

[`RealityViewEntityCollection`](/documentation/RealityKit/RealityViewEntityCollection)

[`ChildCollection`](/documentation/RealityKit/Entity/ChildCollection)

[`EntityCollection`](/documentation/RealityKit/RealityRenderer/EntityCollection)

---

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)