Is it possible to either query a single instance or instruct SwiftData that there should only be a single instance in my model?
I have the following basic structure in a lot of my views to query the first element and use it to display data. There is always only one instance, it is by design.
@Query private var waterData: [WaterData]
var body: some View {
if let data = waterData.first {
EmptyView()
} else {
ContentUnavailableView("Content unavailable", systemImage: "xmark.circle")
}
}
Is there a way to reduce the boilerplate of if let data = ...
in each view?