App
protocol · iOS 14.0+ · SDK 27.1
@MainActor @preconcurrency protocol AppA type that represents the structure and behavior of an app. Create an app by declaring a structure that conforms to the `App` protocol. Implement the required ``SwiftUI/App/body-swift.property`` computed property to define the app's content: @main struct MyApp: App { var body: some Scene { WindowGroup { Text("Hello, world!") } } } Precede the structure's declaration with the [@main](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#ID626) attribute to indicate that your custom `App` protocol conformer provides the entry point into your app. The protocol provides a default implementation of the ``SwiftUI/App/main()`` method that the system calls to launch your app. You can have exactly one entry point among all of your app's files. Compose the app's body from instances that conform to the ``SwiftUI/Scene`` protocol. Each scene contains the root view of a view hierarchy and has a life cycle managed by the system. SwiftUI provides some concrete scene types to handle common scenarios, like for displaying documents or settings. You can also create custom scenes. @main struct Mail: App { var body: some Scene { WindowGroup { MailViewer() } Settings { SettingsView() } } } You can declare state in your app to share across all of its scenes. For example, you can use the ``SwiftUI/StateObject`` attribute to initialize a data model, and then provide that model on a view input as an ``SwiftUI/ObservedObject`` or through the environment as an ``SwiftUI/EnvironmentObject`` to scenes in the app: @main struct Mail: App { @StateObject private var model = MailModel() var body: some Scene { WindowGroup { MailViewer() .environmentObject(model) // Passed through the environment. } Settings { SettingsView(model: model) // Passed as an observed object. } } } A type conforming to this protocol inherits `@preconcurrency @MainActor` isolation from the protocol if the conformance is included in the type's base declaration: struct MyCustomType: Transition { // `@preconcurrency @MainActor` isolation by default } Isolation to the main actor is the default, but it's not required. Declare the conformance in an extension to opt out of main actor isolation: extension MyCustomType: Transition { // `nonisolated` by default }
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
App.main()
Static protocol requirements cannot be called through an instance.