I built a quick WatchOS app that uses an @Model to populate a List within a NavigationSplitView. After several minutes, the List displays the data which is in my CloudKit database - so far so good. Unfortunately, when I attempt to tap on any of the List items, the detail view is never displayed. Here is the ContentView:
import SwiftUI
import SwiftData
struct ContentView: View {
@Query(sort: \Squats.date, order: .reverse) var exercises: [Squats]
@Environment(\.modelContext) var modelContext
@State var selectedExercise: Squats? = nil
var body: some View {
if exercises.count == 0 {
Text("CloudKit not yet loaded")
} else {
NavigationSplitView {
List (exercises, selection: $selectedExercise) { ex in
Text(ex.date.format("E, MM/dd"))
}
} detail: {
Text(selectedExercise?.exercise ?? "Nothing set")
}
.padding()
}
}
}
And here is the model view:
import Foundation
import SwiftData
@Model
class Squats {
var date: Date = Date()
var exercise: String = ""
init(date: Date, exercise: String) {
self.date = date
self.exercise = exercise
}
}
I’ve tried this on a number of my in-production DBs, as well as this development-only “Squats” DB - same lack of detail view on all.
Thoughts?