Group Group Group Group Group Group Group Group Group

Chapter 13: Debugging a nil delegate

The cancel, return key and doneBarButton work inside the AddItemViewController. But when executing code here:

@IBAction func done() {
print(“Contents of the text field: (textField.text!)”)
let item = ChecklistItem()
item.text = textField.text!

delegate?.addItemViewController(self, didFinishAdding: item)
print("post addItemViewController - didFinishAdding")

}

The delegate in delegate?.addItemViewController… is nil:

Debug info

self Checklists_202103_UIK.AddItemViewController 0x00007f8234c103c0
UIKit.UITableViewController UITableViewController delegate
Checklists_202103_UIK.AddItemViewControllerDelegate? nil none
textField UITextField? 0x00007f8234c1a840

Here is the setup code:
class AddItemViewController: UITableViewController, UITextFieldDelegate {

weak var delegate: AddItemViewControllerDelegate?

Any suggestions on how to debug this?

Never mind. I think there is a Murphy’s Law that as soon as I post a question, I resolve the issue. Here, in the Checklists Scene, the identity inspector had class set to AddItemViewController instead of ChecklistViewController. My bad!