0Pricing
SwiftUI Academy · Lesson

Anatomy of a SwiftUI App File

Understand @main, App, WindowGroup, and ContentView.

Anatomy of a SwiftUI App File is a free SwiftUI Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The App File

Every SwiftUI project has a file named after your app, like MyFirstApp.swift. This app file is the true entry point where your whole app begins. 📱

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. 🧩

Frequently asked questions

Is the “Anatomy of a SwiftUI App File” lesson free?

Yes — the full text of “Anatomy of a SwiftUI App File” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.

What will I learn in “Anatomy of a SwiftUI App File”?

Understand @main, App, WindowGroup, and ContentView. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SwiftUI Academy?

No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Anatomy of a SwiftUI App File” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SwiftUI Academy lesson?

Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Installing Xcode & Creating a Project
  2. Anatomy of a SwiftUI App File
  3. The Live Preview Canvas
  4. Running on Simulator & Device
← Back to SwiftUI Academy