All bites
The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.
8668 bites
Page 153
KVO: Swift's Built-In Observer Pattern
KVO lets an object subscribe to property changes on another object automatically. It shines when you need UI updates driven by model state, but forgetting to remove observers before deallocation crashes your app with an NSException.
Thread Sanitizer catches data races in Swift
Thread Sanitizer turns flaky race crashes into reproducible reports by monitoring memory accesses at runtime. Use it in Xcode to catch unsynchronized cross-thread reads and writes. It only catches races that execute during your test run, so coverage matters.
Profiling iOS Memory with Instruments
Instruments X-rays your heap to catch objects that outstay their welcome. Profile image-heavy features or when jetsam kills your app. Never trust Simulator memory numbers; always validate on physical hardware.
@objc: Swift's Bridge to Objective-C
@objc is the bridge badge that exposes Swift code to the Objective-C runtime so UIKit selectors and KVO work. You need it for target-action and Core Data. Forget it and you get a runtime crash, not a compiler error.
XCFrameworks: One Bundle for Every Apple Platform
An XCFramework is a shipping container for compiled Apple libraries: one bundle holds device, simulator, and Mac binaries so Xcode picks the right slice automatically. Use it to distribute closed-source SDKs.
Dependency Resolution in iOS Package Managers
Dependency resolution finds one version of every library that satisfies all transitive requirements. It runs when SPM, CocoaPods, or Carthage builds your graph. The footgun is tight upper bounds; they multiply unresolvable diamond conflicts.
XCTestCase: One Fresh Instance Per Test
A XCTestCase subclass is a lab bench for isolated experiments. Each test method is a fresh invocation checked by the runner. The silent killer is shared mutable state on the case: without setUp, tests flake because execution order is never guaranteed.
MatchedGeometryEffect: Shared Element Hero Transitions
MatchedGeometryEffect lets two views share one spatial identity, so a thumbnail can appear to fly into a detail sheet across view hierarchies. It only works if both views exist simultaneously during a withAnimation block; otherwise the transition snaps.
Custom Rendering with draw(_:)
draw(_:) is the callback where UIKit asks your view for pixels. Override it to render custom shapes or text with Core Graphics when stock views fall short. The footgun is calling it directly or doing non-drawing work inside; use setNeedsDisplay() instead.
withAnimation: The Implicit Animation Transaction
withAnimation wraps state changes in a transaction, telling SwiftUI to tween affected layout automatically. Call it from button actions or view model methods to animate many views from one state flip.
withCheckedThrowingContinuation: Bridge Callbacks to Async/Await
withCheckedThrowingContinuation bridges legacy completion-handler APIs into async/await. Wrap one-shot callback-based work so callers use try await instead of nested blocks. The footgun is resuming twice or never, which checked runtimes catch in debug builds.
Unwind Segues: Jump Back in the Stack
An unwind segue jumps from a deep screen to an earlier view controller without manual popping. Use it after multi-step flows to return to a root screen. If multiple screens share the same action, UIKit picks the nearest one and silently routes users wrong.
Map Data to Views Using navigationDestination
navigationDestination turns NavigationStack into a router: register a view per data type, then push raw values. It frees view models from creating views. Using it outside NavigationStack or mixing it with old NavigationLink destinations silently breaks…
SwiftUI Sheets: State-Driven Modal Overlays
A SwiftUI sheet is a temporary, state-bound overlay that slides over your current view. Use it for focused tasks like composing a message or picking a date. State and environment values do not automatically propagate into its isolated view hierarchy.
TCA: Unidirectional State for SwiftUI
TCA is a strict pipeline for SwiftUI: state and actions enter a pure reducer, emitting new state and effects. Use it when complex flows need reproducible tests without launching the app.
Build Custom Instruments with os_signpost
os_signpost turns code intervals into Instruments graphs by pairing begin-end markers with a visualization package. Use it to correlate app work like model hydration with system CPU and memory metrics. Unmatched begin-end calls break tracks and ruin the view.
Swift Existential Types: The Polymorphism Box
An existential type is a boxed protocol: you see the interface, not the concrete type inside. Use it to store mixed concrete types behind one protocol, like [any Logger]. Prefer generics; existentials hide types and add dynamic dispatch overhead.
Protocol-Oriented Programming in Swift
Protocol-oriented programming swaps inheritance for composable capabilities via protocol extensions. Use it to share behavior across structs without forcing a superclass. The footgun is protocol bloat: indirection without reuse is bureaucracy.
Swift Properties: Accessors in Disguise
A Swift property runs code on every read or write. Use stored properties for state, computed properties for derived values, and observers for side effects. The footgun is heavy work in a computed getter, turning innocent dot syntax into a performance trap.
Swift Closures: Functions with a Memory
A closure is a function carrying luggage: it captures surrounding variables and remembers them later. Use them in SwiftUI actions, async completions, and array transforms. Beware a strong reference cycle from capturing self without a capture list.