1

I am already new in Swift. I run app in simulator. I have list of books, when I click one of them, app shows details about selected book. When I click "Edit Book", change some details and click "Save Book" it paused on line 73

Where is mistake? Why delegate is "nil"? Thanks.

enter image description here

I create protocol and declare "delegate field as follows:

enter image description here

In DetailViewController, I set controller delegate as follows: enter image description here

1 Answers1

2

First, make sure you implement object.delegate = self in the class that you want to conform to the delegate.

Also, I would suggest to implement the method calling by the delegate as:

delegate?.editBook(self, editBook: book)

it this case, nothing would happen if the delegate for some reason is nil instead of crashing.

Furthermore, you might want to check this answer to make sure that you are setup the delegate as it should (probably, you missed the third step from the mentioned answer).

Ahmad F
  • 30,560
  • 17
  • 97
  • 143