After building the project, the search form does not allow typing, but pasting works.

When I created a search box on the homepage, I was able to enter text in the input field while previewing in Xcode. However, after clicking "Build" and running the app, I couldn't type anything into the input field in the demo interface. Additionally, I received the following error message:

  1. If you want to see the backtrace, please set CG_NUMERICS_SHOW_BACKTRACE environmental variable.
  2. 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.

How can I fix this issue? Here is my ContentView.swift code:

import SwiftUI struct ContentView: View { @State private var searchText: String = "" @State private var isSearching: Bool = false

var body: some View {
    NavigationStack {
        GeometryReader { geometry in
            VStack {
                Spacer()
                    .frame(height: geometry.size.height.isNaN ? 0 : geometry.size.height * 0.3)
                
                VStack(spacing: 20) {
                    Text("NMFC CODES LOOKUP")
                        .font(.title2)
                        .bold()
                    
                    TextField("Search...", text: $searchText)
                        .textFieldStyle(PlainTextFieldStyle())
                        .padding(10)
                        .frame(height: 40)
                        .frame(width: geometry.size.width.isNaN ? 0 : geometry.size.width * 0.9)
                        .background(Color.white)
                        .cornerRadius(8)
                        .overlay(
                            HStack {
                                Spacer()
                                if !searchText.isEmpty {
                                    Button(action: {
                                        searchText = ""
                                    }) {
                                        Image(systemName: "xmark.circle.fill")
                                            .foregroundColor(.gray)
                                            .padding(.trailing, 8)
                                    }
                                }
                            }
                        )
                        .overlay(
                            RoundedRectangle(cornerRadius: 8)
                                .stroke(Color.gray.opacity(0.5), lineWidth: 1)
                        )

                    Button(action: {
                        isSearching = true
                    }) {
                        Text("Search")
                            .foregroundColor(.white)
                            .frame(width: geometry.size.width * 0.9, height: 40)
                            .background(Color.blue)
                            .cornerRadius(8)
                    }
                    .disabled(searchText.isEmpty)
                    
                    Text("Created & Designed & Developed By Matt")
                        .font(.caption)
                        .foregroundColor(.gray)
                        .padding(.top, 10)
                }
                
                Spacer()
                    .frame(height: geometry.size.height * 0.7)
            }
            .frame(width: geometry.size.width)
        }
        .background(Color(red: 250/255, green: 245/255, blue: 240/255))
        .navigationDestination(isPresented: $isSearching) {
            SearchResultsView(searchQuery: searchText)
        }
    }
    .background(Color(red: 250/255, green: 245/255, blue: 240/255))
    .ignoresSafeArea()
}

}

#Preview { ContentView() }

The warnings you see are caused by Apple's code, not yours. It relates to displaying a keyboard, so you can ignore those.

Just tried this here and it works fine. iPhone 16 Pro Max 18.2 Simulator.

What happens if you click in the text field in your app in the Simulator, and press Cmd+K to toggle the software keyboard? Does it let you type into the field?

Can you remove/comment out the .overlay that contains the clear button with image xmark.circle.fill. Maybe the tap onto the field is being intercepted by the Spacer() and that image? I don't know, I'm just trying to see what might cause your issue.

Thank you for your help. I tried pressing Command + K in the simulator, but nothing changed; I still can't input any content. I've also commented out the overlay-related code, but I still can't type anything, although I can use the paste function.

It works here. The only difference I had to make on my side was to comment out this, because you didn't supply it:

.navigationDestination(isPresented: $isSearching) {
    SearchResultsView(searchQuery: searchText)
}

You might have to just comment out a 'thing' at a time, i.e. the .textFieldStyle, then the .frame etc.

How about trying it on a different Simulator device.

For Cmd + K, it's just the "Toggle Software Keyboard" option in the "I/O" > "Keyboard" menu. Try going there directly.

@IMZQZ Are you able to reproduce the issue on a physical device? And what OS and build version are you testing on

After building the project, the search form does not allow typing, but pasting works.
 
 
Q