Why it is not same, for example:
func addItemViewControllerDidCancel(_ controller: AddItemViewController)
func itemDetailViewControllerDidAdd(_ controller: ItemDetailViewController, of item: ChecklistItem)
I didn’t find explanation in iOS Apprentice. Is it some kind of best practice? Could anybody explain it to me please?
The two method signatures are different because one has only one parameter (a reference to the AddItemViewController instance) and the second has two parameters (a reference to the AddItemViewController instance and the just added item). If you had only one parameter for the second one, then both method signatures would look much closer …
Not sure if that explains things for you or if your confusion arises from some other point? If that didn’t clarify things, could you explain a bit more in detail as to what confuses you about the two delegate methods?
Then when you call the method, you will have your code something like this:
And that doesn’t really tell anybody else who is reading the code what x is since there is no context/clue as to what that might be when you have two parameters - is the first one the view controller, or is the second one the view controller? It’s not easy to tell (though you can guess that the first probably is the view controller, another developer can always reverse those two …)
With the method naming as addItemViewController(_:didFinishAdding:) it’s much more clearer as to what the parameters are as well as what the action carried out here was.
Of course, if you want to do it the other way, there is nothing stopping you But naming methods in in a way that makes the action as well as the parameters clear, while keeping the code itself concise is what I personally prefer to do. So, it’s also a matter of preference - there’s no right or wrong way. You can go with whatever option you personally prefer …