How to use Xcode in SwiftUI project | SwiftUI Bootcamp #1
Xcode is the IDE where all iOS development happens — understanding its structure and key panels early saves hours of confusion later. After this lesson you'll know how a SwiftUI project is organized on disk, where to find the canvas preview, and how the app entry point connects to your views.
What You'll Learn
- How a SwiftUI project is structured (app entry point vs view files)
- The role of
@main,App, andScenein launching your app - How to use the Xcode canvas to preview views without running the simulator
Mental Model
Think of a SwiftUI project like a theatre production. The @main struct is the stage manager — it exists in exactly one place, calls the opening scene, and hands off control. WindowGroup is the stage itself: it can host one or more performances (windows on iPad/Mac). Each individual View struct is an actor with a specific role. The stage manager doesn't need to know the whole script; it just raises the curtain on the first scene.
The Xcode canvas is like a rehearsal room with mirrors — changes you make in code reflect on the canvas immediately, and you can click elements in the canvas to inspect them, all without building and running the full app.
Detailed Explanation
Every SwiftUI app has exactly one entry point: a struct marked @main that conforms to the App protocol. App requires a body of type some Scene. In most apps that scene is WindowGroup, which wraps your root view and tells the OS "this is the main window."
When Xcode creates a new SwiftUI project it generates two files: the app entry point (SwiftfulThinkingBootcampApp.swift) and a default content view (ContentView.swift). These two files have different responsibilities — the app file manages lifecycle and scene setup, while view files only describe UI.
The Xcode canvas (accessed via the Adjust Editor Options button or ⌘⌥↩) renders live previews defined by your PreviewProvider. Previews are compiled-only code — the PreviewProvider struct is stripped from release builds. You can run multiple previews side by side for different devices, color schemes, or dynamic type sizes.
Code Structure
The sample uses two files. SwiftfulThinkingBootcampApp.swift contains the app entry point that launches the root view. ContentView.swift is a minimal view with a styled Text to confirm the canvas preview pipeline is working. Together they show the minimum viable structure for any SwiftUI app.
Complete Code
SwiftfulThinkingBootcampApp.swift
import SwiftUI
@main // marks this struct as the single entry point the OS calls to start the app
struct SwiftfulThinkingBootcampApp: App {
var body: some Scene {
WindowGroup { // creates the app's main window on all Apple platforms
ResizableSheetBootcamp() // the root view displayed when the app launches
}
}
}ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Placeholder")
.font(.title) // semantic title style — adapts to Dynamic Type
.fontWeight(.black) // heaviest font weight, good for hero text
.foregroundColor(Color.green) // green tint — swap for an asset color in production
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView() // renders in the Xcode canvas; never included in release builds
}
}Code Walkthrough
@main— This attribute tells the Swift compiler which struct is the program's entry point. There can only be one@mainin an app target. Without it, the compiler doesn't know where execution begins.struct SwiftfulThinkingBootcampApp: App— Conforming toApplets SwiftUI manage the app's lifecycle (foreground, background, termination) for you. You rarely need to implement lifecycle methods manually in SwiftUI apps.WindowGroup— A scene type that represents one or more windows showing the same UI. On iPhone it's always one window; on iPad and Mac it can be multiple. SwiftUI handles window restoration automatically.ResizableSheetBootcamp()— This is the first view the user sees. Swap this for any view struct to change the app's launch screen.ContentView— A separate view file. As your app grows, each distinct screen or component lives in its own file. Xcode's project navigator (left panel) shows all your files organized by folder.ContentView_Previews— The preview provider. Xcode compiles this and renders it in the canvas. You can add.previewDevice("iPhone SE (3rd generation)")or.preferredColorScheme(.dark)here to test edge cases.
Common Mistakes
Mistake: Placing logic or network calls in the App struct's body The App body is for scene configuration only — setting up windows, window groups, or menu bar extras. Putting view logic or data loading here makes it impossible to test and impossible to reuse across different scenes. Move all UI logic into dedicated view structs.
Mistake: Having more than one @main in a target If you copy an app template file into a target that already has @main, the compiler will throw a "multiple entry points" error. Make sure only one file in each target carries the @main attribute.
Mistake: Dismissing the Xcode canvas and working only in the simulator The canvas previews update as you type and let you try multiple configurations simultaneously. Relying solely on the simulator means a full compile-and-launch cycle for every change. Use the canvas for rapid iteration and the simulator for full device-specific testing.
Key Takeaways
- Every SwiftUI app has exactly one
@mainstruct conforming toApp— this is the entry point WindowGroupis the most commonSceneand handles window lifecycle across iPhone, iPad, and Mac- The Xcode canvas renders
PreviewProviderstructs at edit time; they are stripped from release builds
Last updated: June 27, 2026