<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/Cancellable/storeWhileEntityActive(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine11CancellableP17RealityFoundationE22storeWhileEntityActiveyyAD0G0CF"
  },
  "title" : "storeWhileEntityActive(_:)"
}
-->

# storeWhileEntityActive(_:)

Retains the `Cancellable` as long as the entity is active (see `Entity.isActive`). If the
entity is deactivated, the `Cancellable` is released.

```
@MainActor @preconcurrency func storeWhileEntityActive(_ entity: Entity)
```

## Discussion

This method does nothing if the entity is already inactive.

Internally, this method stores an `AnyCancellable` in a transient component of the entity.
The component is removed when the *deactivate* event for this entity is received.

---

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)