Swift Cheatsheet - Swift & iOS Development Command Reference
This reference is for Swift developers shipping iOS/macOS apps, command-line tools, or server code, spanning the two toolchains you bounce between: the Swift/SwiftPM CLI and xcodebuild/xcrun simctl. It covers compiling and running scripts, initializing and building Swift packages, building/testing/archiving a scheme, driving simulators, and the syntax idioms (let/var, optional binding, map/filter/reduce) plus debug/assert helpers you reach for daily. Unlike a flat Swift command list, entries are grouped by the actual cycle of compile → test → archive → run on simulator. After reading, you should be able to take a package from swift package init to a passing swift test, and drive an Xcode scheme from the terminal.
Compile & Run 6
swift main.swiftswiftc main.swift -o mainswift main.swiftcswift -e "print("Hello")"swift package init --type executableswift package init --type librarySwift Package Manager 8
swift buildswift build -c releaseswift runswift testswift package resolveswift package updateswift package resetswift package show-dependenciesXcode CLI 7
xcodebuild -listxcodebuild -scheme MyApp buildxcodebuild -scheme MyApp testxcodebuild archive -scheme MyAppxcrun simctl list devicesxcrun simctl boot <device-id>xcrun simctl install booted MyApp.appCommon Syntax 8
var name: String = "Swift"let age: Int = 18if let value = optional { ... }guard let value = optional else { return }array.map { $0 * 2 }array.filter { $0 > 5 }array.reduce(0) { $0 + $1 }for (index, value) in array.enumerated()Debug & Performance 5
print("debug: \(variable)")debugPrint(object)assert(condition, "message")precondition(condition, "message")InstrumentsTips
- swift package init generates Package.swift, the SPM manifest.
- Optionals are core to Swift safety; unwrap with if let / guard let.
- xcodebuild CLI fits CI/CD automated builds and tests.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us