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.
- Introduction — what the Swift target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Swift it renders to.
- Naming considerations — how Program's dotted names are carried into Swift.
- Entry point — starting a program and mounting it as a SwiftUI app.
- Drivers — the native drivers that provide the interface, animation and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Swift behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Swift.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Swift keeps for itself, and how a colliding name is escaped.
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.