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.

Languages·34 commands·Last updated 2026-07-21
Back to Languages

Compile & Run 6

swift main.swift
Run a Swift script
swiftc main.swift -o main
Compile to an executable
swift main.swiftc
Enter the REPL
swift -e "print("Hello")"
Run a one-liner
swift package init --type executable
Init an executable package
swift package init --type library
Init a library package

Swift Package Manager 8

swift build
Build the project
swift build -c release
Build in release mode
swift run
Build and run
swift test
Run tests
swift package resolve
Resolve dependencies
swift package update
Update dependencies
swift package reset
Reset package cache
swift package show-dependencies
Show dependency tree

Xcode CLI 7

xcodebuild -list
List project schemes
xcodebuild -scheme MyApp build
Build a given scheme
xcodebuild -scheme MyApp test
Run tests
xcodebuild archive -scheme MyApp
Archive the project
xcrun simctl list devices
List simulators
xcrun simctl boot <device-id>
Boot a simulator
xcrun simctl install booted MyApp.app
Install to a simulator

Common Syntax 8

var name: String = "Swift"
Mutable variable
let age: Int = 18
Constant
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)
Instruments
Instruments (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