Reduce boilerplate while using @Query (SwiftData)

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?

I believe it was mentioned in one of the WWDC activities that Query should support returning a single model object. As SwiftData is in its early stages anyway, the engineers are open to any feedback and enhancement requests. I suggest you file a feedback report detailing why you want Query to return a single model object as well as any useful use cases they can tailor to.

Reduce boilerplate while using @Query (SwiftData)
 
 
Q