Swift & iOS Setup Guide - CodeSwordsman

Set up Swift and iOS: Xcode command line tools, Swift Package Manager, simulators and device debugging, the Linux toolchain and common error fixes.

Swift 5.10+ / Xcode 15+Updated 2026-10-2927 commands

Install & Version Management

Install the Xcode command line tools on macOS, which include Swift; a full Xcode install is not needed for packages

xcode-select --install
xcodebuild -version
swift --version

Building iOS apps still requires the full Xcode from the App Store plus simulators

Switch the active Xcode path when several versions are installed

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Install the system dependencies required by the official Swift toolchain on Linux

# Linux(Ubuntu 22.04 示例)
sudo apt update && sudo apt install -y binutils git gnupg2 libc6-dev libcurl4-openssl-dev libedit2 libgcc-11-dev libpython3-dev libsqlite3-0 libstdc++-11-dev libxml2-dev libz3-dev pkg-config tzdata zlib1g-dev

Install SwiftLint and SwiftFormat to enforce style and formatting

# macOS
brew install swiftlint swiftformat

Manage multiple Swift toolchains with the official Swiftly on macOS/Linux

swiftly install latest
swiftly use latest

Mirrors & Proxy

Mirror a single dependency for intranet or slow-network setups

swift package config set-mirror --original-url https://github.com/apple/swift-argument-parser --mirror-url https://gitee.com/mirrors/swift-argument-parser

Remove a dependency mirror and restore the original URL

swift package config unset-mirror --original-url https://github.com/apple/swift-argument-parser

SwiftPM fetches through git, so proxy settings belong in the global git config

git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

Clear git proxy settings after turning the proxy off to avoid clone timeouts

git config --global --unset http.proxy
git config --global --unset https.proxy

Environment Variables

Confirm the active developer directory, Swift version and simulator SDK version

xcode-select -p
swift --version
xcrun --sdk iphonesimulator --show-sdk-version

Pin the Xcode path via an environment variable for CI and multi-version setups

echo 'export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer' >> ~/.zshrc

List available simulator devices and their state

xcrun simctl list devices

Accept the Xcode license once, otherwise command-line builds fail

sudo xcodebuild -license accept

Create & Verify

Create an executable package with SwiftPM and run it directly

mkdir hello && cd hello
swift package init --type executable
swift run

Build an optimized binary and run it; the path varies by platform

swift build -c release
.build/release/hello

Run every XCTest in the package

swift test

Resolve and print the dependency tree to trace version conflicts

swift package resolve
swift package show-dependencies

Boot a specific simulator and open the Simulator app

xcrun simctl boot "iPhone 15"
open -a Simulator

IDE & Plugins

Install the official Swift extension in VS Code for completion, debugging and tests

code --install-extension swiftlang.swift-vscode

Open a project in Xcode; for SwiftPM packages you can open Package.swift directly

open -a Xcode hello.xcodeproj

Run tests on a simulator from the CLI, ready for CI

xcodebuild -scheme hello -destination 'platform=iOS Simulator,name=iPhone 15' test

Troubleshooting

Reset the developer directory when xcrun reports an invalid active developer path

xcode-select -p
sudo xcode-select --reset
Risky

Erase and reset simulators when they misbehave; this wipes simulator data

xcrun simctl erase all
Risky

Clear DerivedData when odd build errors persist in Xcode

rm -rf ~/Library/Developer/Xcode/DerivedData

Reset and re-resolve when SwiftPM dependency state is corrupt

swift package reset
swift package resolve

Inspect signing information to debug device install failures and expired certificates

codesign -dv --verbose=4 /path/to/App.app

Check installed runtimes when the target simulator OS is missing

xcrun simctl list runtimes
CodeSwordsman

100+ technical tools with browser-local processing — your data never leaves your device. Official Microsoft Store desktop apps: free, ad-free, offline.

Completely Free

© 2026 CodeSwordsman All Rights Reserved

Service Terms | Privacy Policy | Help | Version Updates | About Us

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.