Question on creating protocol methods

For
protocol ItemDetailViewControllerDelegate: class {
func itemDetailViewControllerDidCancel(_ controller: ItemDetailViewController)
func itemDetailViewController(_ controller: ItemDetailViewController, didFinishAdding item: ChecklistItem)
func itemDetailViewController(_ controller: ItemDetailViewController, didFinishEditing item: ChecklistItem)
}

Why is the first function “did cancel” so different from the others? It only has 1 parameter, and the naming is different than the other 2 functions. Are these functions already provided by Swift, or was this a function we made up?

These names were made up by the programmer (me) but they follow the Cocoa naming conventions (which admittedly are a bit strange sometimes).

It’s customary to place a reference to the “thing” that sends the protocol messages inside the message, which is why we pass along the controller: ItemDetailViewController parameter.

Now, the didFinishAdding and didFinishEditing messages have a second parameter, the ChecklistItem object. But didCancel does not have another parameter, only the reference to controller.

It would have been more consistent to write:

func itemDetailViewController(_ controller: ItemDetailViewController, didCancel)

but that makes didCancel a parameter, but with no value, which does not make sense in Swift.

I hope this explains it a bit better. :smiley: If not, let me know and I’ll try harder!