I'm developing an iOS application using SwiftUI, and I have a custom view called DashboardView which takes an @ObservedObject of type SessionStore.
The problem: the preview does not show at all in Xcode. There's no compile-time error, but I get a message like "Cannot preview this file" or the canvas remains blank.
Here's the relevant part of the code, including the preview:
import SwiftUI
struct DashboardView: View {
@ObservedObject var store: SessionStore
@State private var showCreate = false
@State private var showAddClient = false
@State private var selectedSessionID: UUID?
// Computed properties and body content...
}
// MARK: - Preview
#Preview {
let mockStore = SessionStore()
let session = Session(
id: UUID(),
date: Date(),
title: "Test Session",
people: [
Person(id: UUID(), name: "Alice", debts: [
Debt(id: UUID(), description: "Coffee", amount: 3.5),
Debt(id: UUID(), description: "Sandwich", amount: 5.0)
])
]
)
mockStore.sessions = [session]
return DashboardView(store: mockStore)
}
I expected the preview to show a basic preview of `DashboardView` with mock data from `mockStore`.
What I’ve tried:
- Creating a mock `SessionStore` with sample data in the preview
- Confirmed that `Session`, `Person`, and `Debt` models conform to `Identifiable`, `ObservableObject`, and `Codable`
- Moved all the code into one file and into separate files
- Cleaned the project, restarted Xcode, rebuilt the preview
- Checked for missing initializers or broken views
I still don’t understand why the preview won’t render. No error, just a blank or unavailable canvas. Any help or guidance would be much appreciated.

NavigationViewhas been deprecated for years, useNavigationStackinstead.