RealityView
struct · iOS 18.0+ · SDK 27.1
@MainActor @preconcurrency struct RealityView<Content> where Content : ViewA view that contains RealityKit content. Use `RealityView` to display rich 3D RealityKit content in your app, including content you author in Reality Composer Pro. `RealityView` passes a structure that conforms to ``RealityViewContentProtocol`` to its `make` and `update` closures, which you can use to add and remove RealityKit entities to your view. Here is a simple example showing how you can display a custom ``ModelEntity`` using `RealityView`: ```swift struct ModelExample: View { var body: some View { RealityView { content in if let robot = try? await ModelEntity(named: "robot") { content.add(robot) } Task { // Asynchronously perform any additional work to configure // the content after the system renders the view. } } } } ``` Note that the closure in the example above is `async`, and can be used to load contents from your app's bundle or from any `URL` in the background. While your content is loading, `RealityView` will automatically display a placeholder view, which you can customize using the optional `placeholder` parameter. - Tip: Load your content asynchronously to avoid introducing a hang in your app. You can also use the optional `update` closure on your `RealityView` to update your RealityKit content in response to changes in your view's state. `RealityView` displays your RealityKit content inline in true 3D space, occupying the available space in your app's 3D bounds. The ``RealityViewContent`` type on visionOS, and ``RealityViewCameraContent`` on other platforms represents the content of your `RealityView`. If you want to run code every frame (to do animations or simulations), you can use a ``System`` or directly subscribe to the engine's ``SceneEvents.Update``: ```swift RealityView { content in let entity = ModelEntity(mesh: .generateSphere(radius: 0.1)) content.add(entity) _ = content.subscribe(to: SceneEvents.Update.self) { event in entity.position.y -= Float(event.deltaTime) } } ``` `RealityView` has a flexible size by default, and does not size itself based on the RealityKit content it displays. For more advanced uses of RealityKit, such as subscribing to RealityKit events, performing coordinate conversions, or working with AR capabilities, refer to the ``RealityViewContentProtocol`` types.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
RealityView.body
This protocol needs associated types that cannot yet cross the bridge.
RealityView.init(make:update:placeholder:)
callback cannot propagate synchronous failure
RealityView.init(make:update:)
This Swift callback must itself suspend asynchronously. (nonthrowing, so a rejected promise cannot reach swift)