Targets · Swift · Project setup

Project setup

Everything around the rendered code that makes a working, buildable Swift project.

Contents

How a Program becomes Swift, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.

The files

A rendered Swift program is a Swift package. A command-line or server app uses a Package.swift manifest; a shipping iOS or macOS app wraps the same sources in an Xcode project.

MyApp/
  Package.swift         // manifest: name, targets, dependencies
  Sources/
    Reactive/           // the runtime module (Reactive + Context + drivers)
    MyApp/
      App.swift         // the rendered program
      main.swift        // @main App { WindowGroup { Program.Application({ Main() }, [ Ui.SwiftUI.Driver() ]) } }
// Package.swift
// swift-tools-version:5.9
import PackageDescription

let package = Package(
  name: "MyApp",
  dependencies: [],
  targets: [
    .target(name: "Reactive"),
    .executableTarget(name: "MyApp", dependencies: ["Reactive"]),
  ]
)

Build and run

For a command-line or server build, use the Swift Package Manager. For an app on device or simulator, open the package in Xcode and run.

swift build            # compile
swift run              # build and run (CLI / server)
# app: open Package.swift in Xcode, choose a device, and Run (⌘R)

The generated code and the runtime are ordinary Swift, so the project builds and ships exactly like any other Swift package or Xcode app.