Menu
Coddy logo textTech

The App File

Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 2 of 50.

An app starts at a struct marked @main that conforms to App. Its body holds a WindowGroup, and the view inside it is the first screen the user sees:

@main
struct CoddyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

This is the file Xcode creates for every new app. In these lessons it lives in CoddyApp.swift, which is locked, and you write your screens in ContentView.swift.

A view can carry an accessibility identifier: a name that tests use to find it. It does not change how the view looks:

Text("Good morning")
    .accessibilityIdentifier("greeting")

.accessibilityIdentifier("greeting") is a modifier: a method you call on a view to get a changed view back. Apple's UI tests find views the same way, and the checks in these lessons do too, so when a task gives an identifier, attach it exactly as written.

challenge icon

Challenge

Beginner

Make the screen show Welcome to Coddy, and give that Text the accessibility identifier welcome.

Try it yourself

import SwiftUI

@main
struct CoddyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to SwiftUI

Practice on your own: Swift playground