Master Swift development from the command line 🎯
A comprehensive, hands-on guide to building Swift applications using command-line tools. Perfect for developers who want to automate builds, set up CI/CD pipelines, or understand Swift's build system beyond Xcode's GUI.
- swiftc: Direct Swift compilation with fine-grained control
- Swift Package Manager: Modern dependency management and building
- xcodebuild: Professional iOS app building and distribution
- xcrun: Cross-platform compilation and simulator management
# Install Xcode Command Line Tools
xcode-select --install
# Verify installation
swift --version
xcodebuild -version# Create a simple Swift file
echo 'print("Hello, Swift CLI!")' > hello.swift
# Compile and run
swiftc hello.swift -o hello && ./hello🎉 You just built your first Swift app from the command line!
| Tool | Purpose | Guide | Examples | 
|---|---|---|---|
| swiftc | Direct Swift compilation | 📖 Full Guide | 📁 Examples | 
| Swift Package Manager | Modern build system | 📖 Full Guide | 📁 Examples | 
| xcodebuild | iOS app building | 📖 Full Guide | 📁 Examples | 
| xcrun | Cross-platform tools | 📖 Full Guide | 📁 Examples | 
# Single file compilation
swiftc hello.swift -o hello && ./hello
# Multi-file compilation
swiftc *.swift -o MyApp
# Library compilation
swiftc LibExample.swift \
  -emit-library \
  -emit-module \
  -module-name MyLib \
  -o libMyLib.dylib# Create new project
swift package init --type executable --name MyCLITool
# Build and run
swift build                    # Debug build
swift build -c release         # Release build
swift run MyCLITool            # Run with arguments
swift test                     # Run tests# List project schemes
xcodebuild -list -project MyApp.xcodeproj
# Build for iOS Simulator
xcodebuild -project MyApp.xcodeproj -scheme MyApp \
  -destination 'platform=iOS Simulator,name=iPhone 16' \
  build
# Archive for distribution
xcodebuild -project MyApp.xcodeproj -scheme MyApp \
  -destination 'generic/platform=iOS' \
  -archivePath MyApp.xcarchive \
  archive# Find SDK paths
xcodebuild -showsdks
# Compile for iOS Simulator
xcrun --sdk iphonesimulator swiftc main.swift \
  -target arm64-apple-ios18.5-simulator -o app
# Simulator management
xcrun simctl list devices
xcrun simctl boot "iPhone 16"- Start with swiftc - Learn basic compilation
- Move to SPM - Understand modern Swift development
- Master xcodebuild - Build professional iOS apps
- Explore xcrun - Cross-platform and automation
- 🔄 CI/CD Pipelines: Automate your build process
- 📱 iOS Development: Build and distribute apps
- 🔧 CLI Tools: Create command-line applications
- 📦 Libraries: Build and distribute Swift packages
- 🤖 Automation: Script your development workflow
# Build for multiple platforms
swift build --triple x86_64-apple-macosx14.0
swift build --triple arm64-apple-macosx14.0# Archive and export
xcodebuild -exportArchive \
  -archivePath MyApp.xcarchive \
  -exportPath ./ipa \
  -exportOptionsPlist ExportOptions.plist# Install and launch app
xcrun simctl install booted ./MyApp.ipa
xcrun simctl launch booted com.example.MyAppFound an error or want to add more examples? Contributions are welcome!
- Fork the repository
- Create a feature branch
- Add your improvements
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Apple for the amazing Swift toolchain
- The Swift community for continuous improvements
- All contributors who help make this guide better
⭐ Star this repository if it helped you master Swift CLI development!