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?

Seeing this in UIKit as well on a textfield. Happens when the auto-correct popup appears.

Any updates on this? Experiencing the same issue when the auto-correct function engages, highlighting typed text.

I still see this issue in Xcode 16.2, iOS 18.1.1 ...

First, as of jan 2025 this problem still exists with xcode 16.2 running on the simulator for iphone and ipad.

Second, I see the same message in a simple app with pure objc code whenever I long press on a text field:

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+80> <+[UIBezierPath _continuousRoundedRectBezierPath:withRoundedCorners:cornerRadii:segments:smoothPillShapes:clampCornerRadii:] <+[UIBezierPath _continuousRoundedRectBezierPath:withRoundedCorners:cornerRadius:segments:]+184> <+[UIBezierPath _roundedRectBezierPath:withRoundedCorners:cornerRadius:segments:legacyCorners:]+340> <-[_UITextMagnifiedLoupeView layoutSubviews]+1252> <-[UIView(CALayerDelegate) layoutSublayersOfLayer:]+2404> <_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE+432> <_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE+124> <_ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd+464> <_ZN2CA11Transaction6commitEv+652> <_ZN2CA11Transaction25flush_as_runloop_observerEb+68> <_UIApplicationFlushCATransaction+48> <__setupUpdateSequence_block_invoke_2+352> <_UIUpdateSequenceRun+76> <schedulerStepScheduledMainSection+168> <runloopSourceCallback+80>

...

Not confined to SwiftUI; this also happens in UIKit. And it is still happening in Xcode 16.3 beta.

Has anyone had any luck resolving this? I am in Xcode 16.3, testing on an actual device (iPhone 15 pro with iOS 18.5), but also see on a simulator going back to older iPhones and iOS 17.

The error is occurring on any text field, when autocorrect kicks in, or when I highlight 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.

Even if I create a new swift project, and add the most. basic text field, I get the error.

I can fix by disabling auto-correct, but obviously that is not the best UX. I have attempted various methods of changing the wrapper around the code, adding padding, etc.

Thank you!

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