<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/App",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI3AppP"
  },
  "title" : "App"
}
-->

# App

A type that represents the structure and behavior of an app.

```
@MainActor @preconcurrency protocol App
```

## Overview

Create an app by declaring a structure that conforms to the `App` protocol.
Implement the required [`body`](/documentation/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 [`main()`](/documentation/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 [`Scene`](/documentation/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 [`StateObject`](/documentation/SwiftUI/StateObject) attribute to initialize a
data model, and then provide that model on a view input as an
[`ObservedObject`](/documentation/SwiftUI/ObservedObject) or through the environment as an
[`EnvironmentObject`](/documentation/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
}
```

## Topics

### Implementing an app

[`body`](/documentation/SwiftUI/App/body-swift.property)

The content and behavior of the app.

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

The type of scene representing the content of the app.

### Running an app

[`init()`](/documentation/SwiftUI/App/init())

Creates an instance of the app using the body that you define for its
content.

[`main()`](/documentation/SwiftUI/App/main())

Initializes and runs the app.



---

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)