How it works
UIHostingSceneDelegate is a UIKit scene delegate protocol that lets you drive a scene's window with SwiftUI content rather than a UIKit view-controller hierarchy. Adopt it when your app's lifecycle is still managed through UIKit scenes — for example, an existing UISceneDelegate-based app, or one that needs scene-level control SwiftUI's App and Scene types don't yet expose — but you want each scene's interface authored as a SwiftUI view. The delegate bridges the two worlds: UIKit owns the scene connection and window, while SwiftUI owns what the window draws. Reach for it when you're incrementally moving a scene-based UIKit app toward SwiftUI without rewriting the launch and lifecycle plumbing.
Conform a scene delegate to UIHostingSceneDelegate
Declare a scene delegate type that adopts UIHostingSceneDelegate so UIKit can hand it a connecting scene and let it install SwiftUI content. The protocol marks this object as the SwiftUI-aware delegate for a scene, the place where a SwiftUI view such as
UIHostingSceneDelegateDemobecomes the scene's hosted interface.Supply the root SwiftUI view as the scene's content
The delegate's job is to provide the SwiftUI view that fills the scene's window. Here that root is
UIHostingSceneDelegateDemo, whosebodyreturnssome View; whatever you return from this view — theVStack, theImage, theTextlabels — is what the hosted scene presents, exactly as it would inside a standalone SwiftUI app.Author the interface with ordinary SwiftUI
Because the scene hosts a real SwiftUI view, you compose it with the same declarative API you'd use anywhere else — layout containers,
.font(.headline),.foregroundStyle(.tint),.padding(). UIHostingSceneDelegate imposes no special view requirements; it only ensures the SwiftUI rendering, layout, and environment machinery run inside the UIKit scene that connects to your delegate.Let the delegate participate in the UIKit scene lifecycle
Because it is still a scene delegate, the conforming type sits in the normal UIKit scene-connection path, so scene activation, backgrounding, and window setup flow through it. UIHostingSceneDelegate is what lets that UIKit-managed scene render the SwiftUI
bodyofUIHostingSceneDelegateDemoinstead of a UIViewController.
Text("Hosted Scene Content") label to a Button that toggles a @State property, then run the scene to confirm the hosted SwiftUI view stays fully interactive and stateful inside the UIKit scene.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct UIHostingSceneDelegateDemo: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "rectangle.on.rectangle")
.font(.largeTitle)
.foregroundStyle(.tint)
Text("Hosted Scene Content")
.font(.headline)
Text("A UIHostingSceneDelegate bridges this SwiftUI view into a UIKit scene.")
.font(.caption)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
}
.padding()
}
}