Xcode / Swift Playgrounds
Install Xcode, build your first iOS app with SwiftUI, run it on simulator and device, and ship to TestFlight.
Swift — getting started
EXAMPLE
# ===== 1. Install Xcode (macOS only for iOS dev) =====
# App Store -> Xcode (large download)
# Open once to install command-line tools.
# Verify:
xcode-select -p
swift --version
# For non-Apple Swift (server / Linux):
# - swiftly (recommended) or swift.org installer for Linux
# ===== 2. Hello, Swift (command line) =====
# hello.swift
print("hello, Swift")
swift hello.swift
# ===== 3. Hello, SwiftPM (library / CLI) =====
mkdir hello && cd hello
swift package init --type executable --name hello
# Sources/hello/main.swift:
print("hello from SwiftPM")
swift run
# ===== 4. SwiftUI iOS app =====
# Xcode -> New Project -> iOS -> App
# - Interface: SwiftUI
# - Language: Swift
# Replace ContentView.swift:
import SwiftUI
struct ContentView: View {
@State private var count = 0
var body: some View {
VStack(spacing: 16) {
Text("Clicks: \(count)").font(.title)
Button("+1") { count += 1 }
.buttonStyle(.borderedProminent)
}
.padding()
}
}
#Preview {
ContentView()
}
# Run with Cmd+R; pick a simulator or your physical device.
# ===== 5. On-device debugging =====
# - Connect device via USB
# - Trust the computer on the device
# - Xcode -> Window -> Devices and Simulators -> Pair
# - Sign with your Apple ID team in Xcode > Signing and Capabilities
# ===== 6. Testing =====
# Add a Test target in Xcode. Use XCTest:
import XCTest
class MathTests: XCTestCase {
func testOnePlusOne() { XCTAssertEqual(1 + 1, 2) }
}
# Run: Cmd+U
# ===== 7. Ship to TestFlight =====
# Xcode -> Product -> Archive
# Distribute -> App Store Connect -> Upload
# In App Store Connect, add testers and release.
# ===== 8. Server-side Swift =====
# Vapor: vapor new my-api && cd my-api && swift run
# Hummingbird: also good
# Runs on Linux too with the open-source toolchain.
# ===== Patterns to internalise =====
# - SwiftUI by default for new iOS apps
# - structs + value semantics first; classes only when you need identity
# - Optional types in signatures; resolve at boundaries
# - async / await everywhere I/O happens
# ===== Pitfalls =====
# - Force-unwrapping with ! everywhere -> crashes you would not have in safer code
# - Massive view controllers (UIKit antipattern)
# - Mixing Combine + async / await without a plan
# - Not testing on a real device until release
Why it matters
Install Xcode, open the SwiftUI template, run on simulator, run on device, archive to TestFlight. The five-step iOS first-app loop. The tooling does most of the work; learn SwiftUI + async / await and you can ship serious apps.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
# Install Xcode from the App Store, then: swift --version swift package init --type executable swift runTry it Yourself »
Discussion
Loading…