Swift Basics
| Feature | Example |
| Constants | let name = "Swift" |
| Variables | var count = 0 |
| Type annotation | let score: Double = 95.5 |
| String interpolation | "Hello, \(name)" |
| Arrays | var items = [1, 2, 3]; items.append(4) |
Optionals
| Pattern | Example |
| Optional declaration | var name: String? (may be nil) |
| Optional binding | if let name = name { print(name) } |
| Guard let | guard let name = name else { return } |
| Nil coalescing | let display = name ?? "Unknown" |
Closures
| Syntax | Example |
| Full | { (a: Int, b: Int) -> Int in return a + b } |
| Shorthand | { $0 + $1 } |
| Trailing | array.map { $0 * 2 } |
SwiftUI Quick Start
| Element | Code |
| Text | Text("Hello, World!") |
| Button | Button("Tap") { action() } |
| VStack | VStack { Text("A") Text("B") } |
| State | @State private var count = 0 |
Pro Tip: Force-unwrapping optionals with ! is a code smell. Use if let, guard let, or nil coalescing (??) instead. A crash from force-unwrapping nil is the #1 Swift runtime error in production apps.