<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/CompositorContent",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17CompositorContentP"
  },
  "title" : "CompositorContent"
}
-->

# CompositorContent

A type that describes content a scene renders directly with Metal, rather
than composing from SwiftUI views.

```
@MainActor protocol CompositorContent
```

## Overview

Conform to this protocol when you draw an immersive scene with your own
Metal renderer. Implement [`body`](/documentation/SwiftUI/CompositorContent/body-swift.property) to describe the
content, then pass the type to an [`ImmersiveSpace`](/documentation/SwiftUI/ImmersiveSpace) in place of a view.
The `CompositorLayer` type in CompositorServices gives you the render loop
to draw into.

The following example wraps a renderer in a type that an immersive space
can present:

```
struct StarField: CompositorContent {
    var body: some CompositorContent {
        CompositorLayer(configuration: StarFieldConfiguration()) {
            layerRenderer in
            renderLoop(layerRenderer)
        }
    }
}

@main
struct StarFieldApp: App {
    var body: some Scene {
        ImmersiveSpace {
            StarField()
        }
    }
}
```

Compose these types the same way you compose views: a body can contain
another [`CompositorContent`](/documentation/SwiftUI/CompositorContent), and [`AnyCompositorContent`](/documentation/SwiftUI/AnyCompositorContent) erases the
concrete type when you need to return one of several kinds.

## Topics

### Associated Types

[`associatedtype Body : CompositorContent`](/documentation/SwiftUI/CompositorContent/Body-swift.associatedtype)

### Instance Properties

[`var body: Self.Body`](/documentation/SwiftUI/CompositorContent/body-swift.property)

### Instance Methods

[`func contentCaptureProtected(Bool) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/contentCaptureProtected(_:))

Marks the view as a view that activates content protection
during scene capture events, such as screenshots, screen
recordings, screensharing, etc.

[`func onAppear(perform: (() -> Void)?) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/onAppear(perform:))

Adds an action to perform before this content appears.

[`func onChange(of:initial:_:)`](/documentation/SwiftUI/CompositorContent/onChange(of:initial:_:))

[`func onDisappear(perform: (() -> Void)?) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/onDisappear(perform:))

Adds an action to perform after this content disappears.

[`func onImmersionChange(initial: Bool, (ImmersionChangeContext, ImmersionChangeContext) -> Void) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/onImmersionChange(initial:_:))

Performs an action when the immersion state of your app changes.

[`func onWorldRecenter(action:)`](/documentation/SwiftUI/CompositorContent/onWorldRecenter(action:))

Adds an action to perform when recentering the view with the
digital crown.

[`func persistentSystemOverlays(Visibility) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/persistentSystemOverlays(_:))

Sets the preferred visibility of the non-transient system views
overlaying the app.

[`func preferredSurroundingsEffect(SurroundingsEffect?) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/preferredSurroundingsEffect(_:))

Applies an effect to passthrough video.

[`func upperLimbVisibility(Visibility) -> some CompositorContent`](/documentation/SwiftUI/CompositorContent/upperLimbVisibility(_:))

Sets the preferred visibility of the user’s upper limbs, while an
[`ImmersiveSpace`](/documentation/SwiftUI/ImmersiveSpace) scene is presented.

## Relationships

### Conforming Types

[`Content`](/documentation/SwiftUI/CompositorContentBuilder/Content)

[`AnyCompositorContent`](/documentation/SwiftUI/AnyCompositorContent)

---

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)