是否可以将 newsearable
与 a 结合使用@FetchRequest
?
我有这样的代码:
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")
}
}
}
在这个简单的示例中,我想使用searchText
来过滤我的FetchedResults
.