I am using the searchable modifier on a List of Titles (Entity) stored in CoreData. When I click on a link without the search the NavigationLink opens the View (PlayerView) perfectly. But when I use the search field to search for a specific title and click on the link in the search result the PlayerView opens for just a moment and then pops back to the NavigationView. Is there anybody out there with a hint how to fix that? Here is my code:
struct NavTest: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Title.restid, ascending: false)])
var coreList: FetchedResults<Title>
@State private var searchText = ""
var query: Binding<String> {
Binding {
searchText
} set: { newValue in
searchText = newValue
coreList.nsPredicate = newValue.isEmpty ? nil : NSPredicate(format: "title CONTAINS %@", newValue)
}
}
var body: some View {
NavigationView{
List{
ForEach(coreList, id: \.self) { (item: Title) in
NavigationLink(destination: PlayerView(item.title!)){
Text(item.title!)
}
}
}
.searchable(text: query)
}
}
}