Targets · Swift · Entry point

Entry point

Starting a program and mounting it as a SwiftUI app.

Contents

How a Program becomes Swift, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.

One call, mounted in a scene

A program starts with a single call that takes the root component and the drivers it uses. On Swift the result is a SwiftUI View, so it is placed in the app's WindowGroup — the running program is the root view.

@main
struct CounterApp: App {
  var body: some Scene {
    WindowGroup {
      Program.Application({ Counter() }, [ Ui.SwiftUI.Driver() ])
    }
  }
}

The root component is the run body: its calls emit the interface, its state lives across cycles, and its nesting becomes nested trailing closures (see the example). SwiftUI owns the lifecycle. The model is exactly the JavaScript entry point; only the mount differs.