doneBarButton needs to be disabled at viewDidLoad() first

Dear Author(s),

When I am studying your iOS Apprentice Chapter 2 Checklist app, I’ve found the code:

func textField(_ textField: UITextField,
               shouldChangeCharactersIn range: NSRange,
               replacementString string: String) -> Bool {
    let oldText = textField.text! as NSString
    let newText = oldText.replacingCharacters(in: range, with: string)
        as NSString

    doneBarButton.isEnabled = (newText.length > 0)
    return true
}

is not going to disable the doneBarButton at the first place. User can still press the done button and an empty activity will be add to the checklist’s table view.

A solution will be disable the button before launching the view controller at viewDidload()

override func viewDidLoad() {
    super.viewDidLoad()
    doneBarButton.isEnabled = false
}

By the way, I recently bought your books, it is very awesome, I like it a lot. However, there is still a few details were missing. As in the iOS Apprentice Chapter 1, it will be really nice if you can point out all the constraints for the bull’s eye.

Cheers!
Zack

The book explains that you need to initially disable the Done button in the storyboard (bottom of page 94).

What you’re doing in viewDidLoad is OK too, of course, but not really necessary if you already disable the button in the storyboard.

Oh…I am so sorry, Mr.Hollance, I should read the book more carefully.

Zack