Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Created January 3, 2024 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunlebron/3904745f058b0afae833807be58b6349 to your computer and use it in GitHub Desktop.
Save shaunlebron/3904745f058b0afae833807be58b6349 to your computer and use it in GitHub Desktop.
Syntax of a SwiftUI app

Syntax of a SwiftUI app

The structure of a SwiftUI app uses a lot of Swift syntax to appear simple:

import SwiftUI


@main                         // <-- Attribute (potentially an attached macro)
struct MyApp: App {
    var body: some Scene {    // <-- computed property with implicit get only (using an opaque type satisfying the Scene protocol)
        WindowGroup {         // <-- getter implicitly returning WindowGroup instance with a constructor receiving a closure
            ContentView()     // <-- closure implicitly returning this
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment