Having the same problem, anyone has anything new to help solve the issue?
I have a NavigationSplitView with three columns and a .searchable()on the first column List view. Data to the views come from Core Data @FetchRequest. Whenever user removes a character from the search field or clears the search field, the same warning is displayed. When entering search text, warning does not appear.
This does not happen always. For example when I enter a search text resulting in one row, and then remove one letter from search text. Then three rows are displayed and this warning does not appear. After removing another letter, resulting to five rows appearing, then this warning appears.
Relevant parts of code below.
struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest (sortDescriptors: [SortDescriptor(\.subject)]) private var categories: FetchedResults<Category>
@State private var selectedCategory : Category? = nil
@State private var selectedTerm: Term? = nil
@State private var searchText = ""
var body: some View {
NavigationSplitView {
List(selection: $selectedCategory) {
ForEach(categories, id: \.self) { category in
CategoryRowView(category: category)
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
toDeleteCategory = category
showDeleteCategoryConfirmation.toggle()
} label: {
Label("Delete", systemImage: "trash")
}
}
}
}
.listStyle(.sidebar)
.searchable(text: $searchText)
...
} content: {
if let category = selectedCategory {
List(category.viewTerms(filter: searchText.isEmpty ? nil : searchText), id: \.self, selection: $selectedTerm) { term in
and the implementation of category.viewTerms(filter: ) that does the filtering based on searchText (Category is a Core Data class):
extension Category {
...
func viewTerms(filter: String?) -> [Term] {
var terms = viewTerms
if filter != nil {
terms = terms.filter( { $0.termSearchText.localizedCaseInsensitiveContains(filter!) } )
}
return terms
}
var viewTerms: [Term] {
let terms = categoryTerms?.allObjects as? [Term] ?? []
return terms.sorted(by: {$0.viewPrimaryName < $1.viewPrimaryName } )
}
Where the Category.categoryTerms is a one-to-many Core Data relationship from Category entity to Term entity.