Two SwiftData @Query Pitfalls — enum #Predicate and modelContext on Empty Lists

The Setup I was building Inbox/Archive list views for a document scanning app. Simple enough: filter documents by status using SwiftData’s @Query. Two compile-time surprises were waiting. Pitfall 1: #Predicate Can’t Compare Enums What I Wrote The natural approach: @Model class Document { var status: DocumentStatus // enum stored property // ... } enum DocumentStatus: String, Codable { case inbox, archived } Then in the view: @Query( filter: #Predicate<Document> { $0.status == .inbox }, sort: \Document.createdAt, order: .reverse ) private var documents: [Document] Looks clean. Doesn’t compile. ...

April 26, 2026 · 3 min · Young

Why Naming Your SwiftData Model 'Tag' Breaks Your Build (+ Xcode 16 .gitkeep Trap)

What I Was Trying to Do I started a new document scanning app and was setting up SwiftData models using TDD. Simple Document and Tag models: @Model class Tag { var name: String var color: String @Relationship(inverse: \Document.tags) var documents: [Document] } Built fine. No issues so far. Trap #1: That’s Not Your Tag The moment I used FetchDescriptor in a test file, it blew up: let fetched = try context.fetch(FetchDescriptor<Tag>()) error: 'Tag' is ambiguous for type lookup in this context Turns out SwiftUI already has a Tag type — the one used for identifying selection items in TabView and Picker. When your test file imports both @testable import scansort and SwiftUI (via SwiftData), the compiler can’t decide which Tag you mean. ...

April 26, 2026 · 3 min · Young

Why Your SwiftData + CloudKit Widget Shows No Data (And How to Fix It)

The Widget Was Empty JournalMind syncs journal data with SwiftData + CloudKit. When I added a home screen widget to show today’s mood and weekly graph, the widget was always blank — even though the app itself showed data just fine. The Cause: Separate Processes A WidgetKit extension runs in a separate process from the main app. Even if you create the same ModelContainer, CloudKit sync only happens in the main app’s process. ...

April 21, 2026 · 4 min · Young