concept bookviewcontroller in category ios

This is an excerpt from Manning's book iOS Development with Swift.
Add the info button in the viewDidLoad method of BookViewController: let infoButton = UIButton(type: .infoLight) 1 bookCover.addSubview(infoButton) 2
- 1 Creates info button
- 2 Adds info button to book cover
In the viewDidLoad method, the BookViewController should check if the book object exists, and if it does, prefill the fields. If a book object exists, you know that you’re editing rather than creating a book. Take the opportunity to adjust the navigation bar’s title accordingly. Be sure to fill the fields before checking if the Save button should be enabled. if let book = book { 1 bookCover.image = book.cover 2 titleTextField.text = book.title 2 authorTextField.text = book.author 2 isbnTextField.text = book.isbn 2 notesTextView.text = book.notes 2 navigationItem.title = "Edit book" 3 } saveButton.isEnabled = !titleTextField.text!.isEmpty 4
- 1 Unwraps book object
- 2 Prefills form fields with book
- 3 Changes navigation bar title
- 4 Disables Save button if no title
First, what caused the problem? The exception information should answer this important question, and ironically, it’s often scrolled offscreen by the call stack! Ignore the time codes and memory addresses and look for the description of the exception in English. According to the exception information in this case, there was an NSUnknownKey-Exception for the key titleL in the BookViewController.
It appears that in the BookViewController class, a selector (that is, a method) called touchCancel is being called but not recognized. Why would that be, and what was happening at the time? You probably have enough information to take a good, educated guess, but let’s look at a portion of the call stack for more clues. See figure 15.8—again, I’ve emphasized part of the output to help you focus on more-interesting details.