Swift Cheatsheet - Swift & iOS Development Command Reference
All essential Swift commands organized by use case, with 34+ entries you can copy and run directly. Find the right command fast when you need it.
Back to LanguagesCompile & Run 6
swift main.swiftRun a Swift script
swiftc main.swift -o mainCompile to an executable
swift main.swiftcEnter the REPL
swift -e "print("Hello")"Run a one-liner
swift package init --type executableInit an executable package
swift package init --type libraryInit a library package
Swift Package Manager 8
swift buildBuild the project
swift build -c releaseBuild in release mode
swift runBuild and run
swift testRun tests
swift package resolveResolve dependencies
swift package updateUpdate dependencies
swift package resetReset package cache
swift package show-dependenciesShow dependency tree
Xcode CLI 7
xcodebuild -listList project schemes
xcodebuild -scheme MyApp buildBuild a given scheme
xcodebuild -scheme MyApp testRun tests
xcodebuild archive -scheme MyAppArchive the project
xcrun simctl list devicesList simulators
xcrun simctl boot <device-id>Boot a simulator
xcrun simctl install booted MyApp.appInstall to a simulator
Common Syntax 8
var name: String = "Swift"Mutable variable
let age: Int = 18Constant
if let value = optional { ... }Optional binding
guard let value = optional else { return }Early exit (guard)
array.map { $0 * 2 }Map
array.filter { $0 > 5 }Filter
array.reduce(0) { $0 + $1 }Reduce
for (index, value) in array.enumerated()Enumerate with index
Debug & Performance 5
print("debug: \(variable)")Print debug info
debugPrint(object)Pretty-print (with type)
assert(condition, "message")Assert (debug builds)
precondition(condition, "message")Precondition (all builds)
InstrumentsInstruments (Xcode profiler)
Tips
- 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
Commands are compiled from the official docs below. Click to verify the latest usage.
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