Member-only story
SwiftUI L-4
4 min readDec 17, 2024
@main
struct SwiftUIApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
@main
:
This attribute marks the entry point of the application.
The name SwiftUIApp
is the app's struct name, which conforms to the App
protocol.
The App
protocol is the entry point for a SwiftUI app.
var body: some Scene
:
Every SwiftUI app must have a body
property that returns a Scene.
- A
Scene
represents a container for the user interface.
some Scene
:
- The
some
keyword indicates Opaque Return Types. - It means that the property will return a specific type of
Scene
, but the exact type doesn’t need to be explicitly stated.
WindowGroup
:
WindowGroup
creates a new window scene for the app.- This is typically used as the root container of your SwiftUI app.
WindowGroup
supports multiple windows on platforms like macOS and iPadOS.
ContentView()
:
- This is the initial view of the app.
ContentView
is a SwiftUIView
that defines the layout and content of the app's UI.
This structure eliminates the need for AppDelegate
or SceneDelegate
files, simplifying the app's architecture.