What does this error mean when using .searchable()

I am getting the following error when trying to use the .searchable() modifier in a SwiftUI application:

Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored. Please fix this problem.
If you want to see the backtrace, please set CG_NUMERICS_SHOW_BACKTRACE environmental variable.

Here is the code that replicates the error for me:

import SwiftUI

struct ContentView: View {
    @State private var searchText = ""
    
    var body: some View {
        NavigationStack {
            Text("Searching for \(searchText)")
                .navigationTitle("Searchable Example")
        }
        .searchable(text: $searchText)
    }
}

Seems like a simple use of the modifier and I can't imagine this is a problem on my side. Is it just log noise to be ignored? If so is there some way to suppress these warnings? Or am I using the modifier incorrectly somehow?

That's because you search in an empty List.

Here is a small example:

struct ContentView: View {

    @State private var searchText = ""
    @State var resultArray = ["Easy", "Medium", "Hard"]

    let fullArray: [String] = ["Easy", "Medium", "Hard"]
    var searchResults: [String] {
        if searchText.isEmpty {
            return fullArray
        } else {
            return fullArray.filter { $0.lowercased().contains(searchText.lowercased()) }
        }
    }


    var body: some View {
        NavigationStack {
            Text("Searching for \(searchText)")
                .navigationTitle("Searchable Example")
            List {
                ForEach(resultArray, id: \.self) { level in
                        Text("\(level)")
                }
                
            }
            .searchable(text: $searchText)
            .onChange(of: searchText, initial: false) {value, _ in
                resultArray = searchResults
            }
        }
    }
}

In a template app running on a simulated iPhone 15, I don't see the error you describe. There must be more to your code than what you show in your example Content(), or it only shows up on a real device, or it only occurs on something other than iOS? I'm using Xcode 15.1 on macOS 14.1.2, simulating iOS 17.2

Did you try setting the CG_NUMERICS_SHOW_BACKTRACE environment variable, and if so, did it give you any further insight?

@RodneyA you are right, a List is not needed. But I just didn't understand what search means in your context. List example was just to show a typical case.

BTW: no such error in simulator with Xcode 15.0.1 and iOS 17.0.

What versions are you using ?

What does this error mean when using .searchable()
 
 
Q