I am getting a Closure containing a declaration cannot be used with result builder ‘ViewBuilder error when moving a function around in SwiftData so I can make a filter using a search bar.
I did some basic research and couldn’t find a a correct fix the error is coming by the init, and func deleteMed
@Environment (.modelContext) var modelContext
@Query var med: [Meds]
var body: some View {
List {
ForEach(med) { meds in
NavigationLink(value: meds) {
Text(meds.name)
Text(meds.dose)
}
}
.onDelete(perform: deleteMed)
init(searchString: String = "") {
_med = Query(filter: #Predicate { med
in
true
})
}
func deleteMed(at offset: IndexSet) {
for offset in offset {
let med = med[offset]
modelContext.delete(med)
}
}
}```
New contributor
user24623563 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.