Swift Foundation
UserDefaults.bool(forKey:) Returns false for a Key You Never Set. Your 'On by Default' Setting Ships Off.
UserDefaults.bool(forKey:) can't tell 'the user turned this off' from 'nobody has ever touched this', so every setting that's supposed to default to true quietly starts as false. Here's why, how register(defaults:) fixes it, why the @AppStorage inline default only fixes it for one view, and the widget and first-launch traps sitting right next to it.
9 min read
SwiftUI AppStorage
@AppStorage Looked Like Free State Management. It Isn't Watching What You Think.
@AppStorage feels like @State that happens to persist. It's actually a thin wrapper over UserDefaults with a KVO bridge bolted on, and that difference bites the moment a widget, an app extension, or a background task touches the same key.
6 min read