0Pricing
SwiftUI Academy · Lektion

Aufbau einer SwiftUI-App-Datei

Verstehen Sie @main, App, WindowGroup und ContentView.

Aufbau einer SwiftUI-App-Datei ist eine kostenlose SwiftUI Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des SwiftUI Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

The App File

Jedes SwiftUI-Projekt hat eine Datei, die nach Ihrer App benannt ist, wie MyFirstApp.swift. Diese App-Datei ist der eigentliche Einstiegspunkt, an dem Ihre gesamte App beginnt. 📱

The @main Marker

The @main attribute tells Swift exactly where your program starts. iOS launches your app by running the type marked with it.

@main
struct MyFirstApp: App {
}

Conforming to App

Your main struct conforms to the App protocol. This is the SwiftUI blueprint for an application, describing what scenes it shows.

The body Property

Inside the App struct, a body property describes your app's scenes. SwiftUI reads it to know what to display when the app launches.

var body: some Scene {
    WindowGroup {
        ContentView()
    }
}

Scenes, Not Views

The app's body returns a Scene, not a View. A scene is a container for a window or screen that holds your actual views inside it.

WindowGroup

WindowGroup is the most common scene. It manages your app's main window and, on iPhone, simply fills the whole screen.

Your Root View

Inside WindowGroup you place your root view, usually ContentView(). It is the first screen the user sees when the app opens.

ContentView Lives Apart

ContentView sits in its own file, separate from the app file. Keeping the entry point and the UI apart keeps your project tidy and clear.

How It Flows

The chain is simple: @main starts the App, the App shows a WindowGroup, and the WindowGroup displays your ContentView. ✨

One @main Only

An app can have just one @main entry point. The template already provides it, so you rarely add or change this part yourself.

Where You Work

You will spend most of your time editing views like ContentView, not the app file. The app file mostly just wires everything together.

Quick Check

What is the job of the WindowGroup scene in the app file?

Recap

You learned the chain: @main on the App struct returns a WindowGroup scene that shows ContentView. That is how a SwiftUI app boots up. 🧩

Häufig gestellte Fragen

Ist die Lektion „Aufbau einer SwiftUI-App-Datei“ kostenlos?

Ja — der vollständige Text von „Aufbau einer SwiftUI-App-Datei“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des SwiftUI Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Aufbau einer SwiftUI-App-Datei“?

Verstehen Sie @main, App, WindowGroup und ContentView. Du übst SwiftUI Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um SwiftUI Academy zu starten?

Keine Vorkenntnisse erforderlich. SwiftUI Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Aufbau einer SwiftUI-App-Datei“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser SwiftUI Academy-Lektion Code schreiben und ausführen?

Ja. Jede SwiftUI Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Xcode installieren und ein Projekt erstellen
  2. Aufbau einer SwiftUI-App-Datei
  3. Die Live-Preview-Arbeitsfläche
  4. Auf Simulator und Gerät ausführen
← Zurück zu SwiftUI Academy