UITextField asserts in console on keyboard long press

I noticed that a very basic code would produce a consistent console assert while editing almost every time keyboard long press is used (e.g. long pressing a letter would bring up a list of alternatives, like u, ü, etc).

Code Block text
2021-04-02 17:37:33.170756-0700 test[4255:2036410] [Assert] View <(null):0x0> does not conform to UITextInput protocol


Simplified code:

Code Block swift
import UIKit
class ViewController: UIViewController {
var textField : UITextField!
override func loadView() {
textField = UITextField()
textField.text = "test"
textField.frame = CGRect(x: 100, y: 100, width: 100, height: 20)
let view = UIView()
view.backgroundColor = .white
view.frame = CGRect(x: 100, y: 100, width: 100, height: 20)
view.addSubview(textField)
self.view = view
}
}


Details:
  • running on physical device

    • iPhone 11 Pro

    • iOS 14.4.2 (18D70)

    • keyboard seems to be standard

  • also reproducible on simulator:

    • iPhone 11 Pro, iOS 14.4 (18D46)

  • but not happening on simulator:

    • iPhone 11 Pro, iOS 13.7 (17H22)

  • similar SwiftUI-based code also has the same issue

Seems like a regression to me, but I'm also open to possibility of something being wrong with my specific configuration (code or otherwise).


Questions:
  • is anyone else experiencing the same issue?

  • any workarounds / fixes?



Yes even I am facing this issue. I haven't been able to figure out any workaround as of now. Doesn't have any impact on the app behaviour though
I tested and reproduced on simulation, Xcode 12.4, iOS 14.4.
With a UITextField simply defined in IB.
2021-05-18 11:24:05.545395+0200 simpleTest[36988:3772658] [Assert] View <(null):0x0> does not conform to UITextInput protocol

Did you file a bug report ?

I sent one: May 18, 2021 at 11:32 AM – FB9109892

Could you look at the textfield's .interactions (in the debugger) property, find a UITextInteraction instance and get its textInput property?

@frameworksengineer I'm also running into this in iOS 15 in a UIKit app. When it happens the textField isn't visible anymore, although I still see it in the View Debugger. I think it happens when I enter some text and then tap outside the textField.

I see the Assert warnings a number of times and also this one: WARNING: Calling updateFocusIfNeeded while a focus update is in progress. This call will be ignored.

I did what you ask and the UITextField.interactions[UITextInteraction].textInput property is simply the UITextField.

(lldb) po (UITextField*)0x7f9fd7c2d200
<UITextField: 0x7f9fd7c2d200; frame = (0 0; 484 25); opaque = NO; gestureRecognizers = <NSArray: 0x7f9fc685d6f0>; text = '1.99'; borderStyle = None; background = <_UITextFieldNoBackgroundProvider: 0x7f9fe29e0120: textfield=<UITextField 0x7f9fd7c2d200>>; layer = <CALayer: 0x7f9fe29e3f20>>

(lldb) po ((UITextField*)0x7f9fd7c2d200).interactions
<__NSArrayI 0x7f9fccbb1600>(
<UIDragInteraction: 0x7f9fc68702b0>,
<UIDropInteraction: 0x7f9fc6830220>,
<_UITextMenuLinkInteraction: 0x7f9fc6880dd0>,
<UIContextMenuInteraction: 0x7f9fc6881600>,
<_UIClickPresentationInteraction: 0x7f9fc68819e0>,
<UIPointerInteraction: 0x7f9fc6875dc0>,
<_UIKeyboardBasedTextSelectionInteraction: 0x7f9fc4b71ef0>,
<UITextInteraction: 0x7f9fc4b905a0>,
<UITextLoupeInteraction: 0x7f9fc4b52d10>,
<UITextSelectionInteraction: 0x7f9fc4be4620>,
<UITextIndirectKeyboardInteraction: 0x7f9fc4bfed80>,
<UITextIndirectEditableInteraction: 0x7f9fe17fc190>,
<UITextLoupeInteraction: 0x7f9fe17c0d70>,
<UITextSelectionInteraction: 0x7f9fdb696510>
)

(lldb) po (UITextInteraction*)0x7f9fc4b905a0
<UITextInteraction: 0x7f9fc4b905a0>

(lldb) po ((UITextInteraction*)0x7f9fc4b905a0).textInput
<UITextField: 0x7f9fd7c2d200; frame = (0 0; 484 25); opaque = NO; gestureRecognizers = <NSArray: 0x7f9fc685d6f0>; text = '1.99'; borderStyle = None; background = <_UITextFieldNoBackgroundProvider: 0x7f9fe29e0120: textfield=<UITextField 0x7f9fd7c2d200>>; layer = <CALayer: 0x7f9fe29e3f20>>

After more investigation it looks like the problem was caused by removingFromSuperview() the textField while it was being edited. My code was removing and re-adding the textField. Removing that code seems to have fixed this. My textField is in a tableView and calling reloadData() while the textField is being edited causes the Warning about updateFocusIfNeeded but that seems to be benign.

UITextField asserts in console on keyboard long press
 
 
Q