Invalid Numeric Value (NaN) Error in SwiftUI's TextField on Long-Press

I'm experiencing a peculiar issue with SwiftUI's TextField. Whenever I long-press on the TextField, the console outputs an error about passing an invalid numeric value (NaN, or not-a-number) to the CoreGraphics API. This issue persists even in a new Xcode project with minimal code.

Code Snippet:

import SwiftUI

struct ContentView: View {
    @State private var text: String = ""

    var body: some View {
        TextField("Placeholder", text: $text)
    }
}
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.

Steps to Reproduce:

Create a new SwiftUI project in Xcode. Add a TextField to the ContentView. Run the app on a device or simulator. Long-press inside the TextField. What I've Tried:

  • Updating to the latest version of Xcode and iOS.
  • Using UIViewRepresentable to wrap a UIKit UITextField.
  • Creating a new Xcode project to isolate the issue.
  • None of these steps have resolved the issue.

Questions:

  • Has anyone else encountered this problem?
  • Are there any known workarounds for this issue?
  • Is this a known bug, and if so, has it been addressed in any updates?

I'm encountering this as well. I wasn't sure what was tripping the error, but after seeing your post, I can confirm that it's a long press.

I am seeing the same problem. This also happens in UIKit. A "long press" on the TextField reproduces the problem. Adding a UITextField inside a View is enough the reproduce the problem. I think this is a bug that Apple should address?

I have the same issue .. however .. while it does occur on a long press, it also occurs anytime I type in the textfield. Occurs with minimal code example, in simulator and on device - using both on-screen keyboard and hardware keyboard. Driving me insane!!

Adding CG_NUMERICS_SHOW_BACKTRACE to Environment Variables as the error suggests, provides the following backtrace. I don't find it very informative - but perhaps it can provide some clues to other more intelligent individuals:

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.
Backtrace:
  <CGPathMoveToPoint+84>
   <+[UIBezierPath _continuousRoundedRectBezierPath:withRoundedCorners:cornerRadii:segments:smoothPillShapes:]+1120>
    <+[UIBezierPath _continuousRoundedRectBezierPath:withRoundedCorners:cornerRadius:segments:]+180>
     <+[UIBezierPath _roundedRectBezierPath:withRoundedCorners:cornerRadius:segments:legacyCorners:]+340>
      <-[_UITextChoiceAccelerationBubble backgroundImageView]+156>
       <-[_UITextChoiceAccelerationBubble anchorToTextIfNeeded]+500>
        <-[_UITextChoiceAccelerationBubble updateTextAnchorForParentView:]+156>
         <-[_UITextChoiceAccelerationBubble updateTextBoxHighlightForRect:inTextView:parentView:highlightColor:]+88>
          <-[_UITextChoiceAccelerationAssistant updateActivePromptForCandidate:displayRects:highlightOnly:]+352>
           <-[UIKeyboardImpl updateAutocorrectPrompt:correctionRects:]+492>
            <-[UIKeyboardImpl updateAutocorrectPrompt:executionContext:]+608>
             <__45-[UIKeyboardImpl touchAutocorrectPromptTimer]_block_invoke+112>
              <__56-[UIKeyboardScheduledTask handleDeferredTimerFiredEvent]_block_invoke+184>
               <-[UIKeyboardTaskEntry execute:]+200>
                <-[UIKeyboardTaskQueue continueExecutionOnMainThread]+304>
                 <-[UIKeyboardTaskQueue addTask:]+92>
                  <-[UIKeyboardScheduledTask handleDeferredTimerFiredEvent]+216>
                   <__invoking___+144>
                    <-[NSInvocation invoke]+276>
                     <-[_UIActionWhenIdle invoke]+52>
                      <__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+32>
                       <__CFRunLoopDoObservers+528>
                        <__CFRunLoopRun+968>
                         <CFRunLoopRunSpecific+572>
                          <GSEventRunModal+160>
                           <-[UIApplication _run]+868>
                            <UIApplicationMain+124>
                             <OUTLINED_FUNCTION_70+500>
                              <OUTLINED_FUNCTION_70+148>
                               <OUTLINED_FUNCTION_2+92>
                                <$s16FurtherIsolation0aB3AppV5$mainyyFZ+40>
                                 <main+12>
                                  104d81558
                                   104e62058                                    3125800000000000

On staring at the backtrace, and seeing continuousRoundedRectBezierPath:withRoundedCorner and UITextMagnifiedLoupeView makes me think the error occurs whenever the new "pill shaped" text selection magnifier appears (long pressing is one case in which this text selection magnifier appears).

I think this is a bug on Apple's side. But surprised there is not more comments on the forums / StackOverflow, etc about this.

I can create a workaround to the issue by preventing the default long press and autocorrection behaviours (which will cause magnifiers or correction suggestions).

For me at least, this stops the warning (but - obviously - prevents text selection and autocorrection).

struct ContentView: View {
    @State private var text: String = ""
    @FocusState private var textfieldFocused: Bool
    
    var body: some View {
        TextField("Placeholder", text: $text)
            .focused($textfieldFocused)
            .onLongPressGesture(minimumDuration: 0.0) {
                textfieldFocused = true
            }
            .autocorrectionDisabled()
    }
}

Report filed via Feedback Assistant: FB13276843

Please file reports too - so that we can can some action on this. :)

I'm getting a similar message in the console but doing something completely unrelated. I am using the latest API of SwiftCharts with .ChartScrollableAxes(). On My chart, I'm adding a .annotation() that appears when tapping on a point in the chart. If I have the annotation showing and then I change the scale of my chart (say tapping 'year' scale instead of 'month' scale, then I get the console message.

Very weird and unrelated but I'll file a report too.

Console message: "[Unknown process name] 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. [Unknown process name] If you want to see the backtrace, please set CG_NUMERICS_SHOW_BACKTRACE environmental variable."

iOS 17.2, Xcode Version 15.1 The problem has not yet been resolved.


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.

iOS 17.2 Xcode 15.1 This is happening for me on typing in textFields that have the textFieldStyle .roundedBorder applied. This is a system defined textFieldStyle so it looks like apple has a bug on their hands somewhere.

If i remove this modifier the warnings stop.

I have similar issue. Adding the .autocorrectiondisabled() helps but then I commented out my .clipshape and .overlay and still have warnings.

Question: Are the warnings going to break anything? If the application will crash, it is a problem. I just getting warnings with no negative impact on my app running.. maybe ok to ignore until fixed ?

I just opened my app in the new Xcode Beta and sure enough it is still there. Would love if Apple Engineers chimed in as to how to get rid of this issue or perhaps how to avoid it.

I think I'm getting the same or similar issue. Not a long press; but as I'm typing, the second TextEdit field in the View about 4 characters in. I can't make head not tail of the Backtrace.

The View is called from a button in the NavigationBarItems using a NavigationLink.

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. Backtrace: <CGPathAddLineToPoint+92> <<redacted>+1336> <<redacted>+188> <<redacted>+344> <<redacted>+160> <<redacted>+504> <<redacted>+160> <<redacted>+92> <<redacted>+356> <<redacted>+512> <<redacted>+596> <<redacted>+116> <<redacted>+208> <<redacted>+208> <<redacted>+324> <<redacted>+96> <<redacted>+256> <<redacted>+148> <<redacted>+428> <<redacted>+56> <<redacted>+36> <<redacted>+552> <<redacted>+1028> <CFRunLoopRunSpecific+608> <GSEventRunModal+164> <<redacted>+888> <UIApplicationMain+340> <<redacted>+414604> <<redacted>+72024> <<redacted>+120596> <$s11MyApp0aB3AppV5$mainyyFZ+40> <main+12> <<redacted>+2240>

I have the same problem, but it's present on all textfields and textformfields I have in my app (made in Flutter), regardless if they have rounded borders or not.

Here's hoping they have a Radar for this back there.

Invalid Numeric Value (NaN) Error in SwiftUI's TextField on Long-Press
 
 
Q