Search code examples
swiftuitextfielddelegate

What is missing from this minimal UITextFieldDelegate implementation, to cause crashing?


The crash occurs upon selecting the Text Field in the simulator. The debugger seems to tell me nothing useful.

import UIKit
class TextField: NSObject, UITextFieldDelegate {}

In the View Controller:

override func viewDidLoad() {
    super.viewDidLoad()
    textField.delegate = TextField()
}
@IBOutlet weak var textField: UITextField! // assigned in IB.

Solution

  • UITextField.delegate is unowned, so the delegates were being deallocated after viewDidLoad returned.