Start a macOS app

Create a macOS SwiftUI project

Create the correct Xcode target, name the product deliberately, and verify the app launches as a native Mac application.

You need Xcode to build Mac apps. Get it from the Mac App Store, open it, and choose File → New → Project.

Pick the macOS tab, then the App template. This choice matters more than it looks. The iOS template creates a different kind of target with different capabilities, and converting later is tedious work.

On the options screen choose SwiftUI for the interface and Swift for the language. Then name the product. Pick a name you won’t regret, because it shows up everywhere. We’ll build a notes app throughout this course, so Notes works well.

The bundle identifier

Take a moment on the organization identifier. Xcode joins it with the product name to build the bundle identifier, something like com.flaviocopes.Notes.

macOS uses this string as the identity of your app. Preferences, Keychain items, and notifications are all tied to it. Use a reverse-DNS name for a domain you control, and treat it as permanent.

Run the template first

Before writing any code, press Cmd+R and run the untouched template. You should see a resizable window with “Hello, world!” in the middle, and the app name in the menu bar next to the Apple menu.

This is your working baseline. If something breaks later, you know it was your change, not the toolchain.

Xcode generated two Swift files. The entry point looks like this:

import SwiftUI

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

We’ll go through every line of this in the next lesson. For now, notice how small it is. No storyboard, no window setup code, no app delegate boilerplate. A SwiftUI app on macOS starts from a declaration.

Check the target settings

Click the project in the navigator, then the Notes target, and open the General tab. Write down the bundle identifier, the deployment target, and the version and build numbers. Set the deployment target to macOS 14 for this course.

These values follow the app through its whole life, from the first debug build to the release you eventually share with people.

Make a git commit right now, before touching anything. When a later change breaks the build in a confusing way, a diff against the known-working template answers questions faster than guessing does.

One mistake I see often

People pick the Multiplatform template because it sounds more capable. It’s not what you want here. It adds iOS assumptions you don’t need, and the extra conditional compilation gets in the way while you learn.

Choose the plain macOS App template. You can add more destinations later from the target settings if you ever want them.

Lesson completed