Is it possible to use the new .searchable
in combination with @FetchRequest
?
I have a code like this:
struct FooListView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \Foo.name, ascending: true)],
animation: .default)
private var items: FetchedResults<Foo>
@State var searchText = ""
var body: some View {
NavigationView {
List {
ForEach(items) { item in
NavigationLink(destination: FooView(Foo: item)) {
Text(item.wrappedName)
}
}
.onDelete(perform: deleteItems)
}
.searchable(text: $searchText)
.navigationTitle("Foos")
}
}
}
I would like to use the searchText
to filter my FetchedResults
.