I do apologize in advance for asking such a silly question, yet I didn't quite get what I wanted to know from the other answers out there. Here is the sample code of custom delegate protocol from the Ray Wenderlich iOS course
protocol AddItemViewControllerDelegate: class {
func addItemViewControllerDidCancel(_ controller: AddItemViewController)
func addItemViewController(_ controller: AddItemViewController,
didFinishAdding item: ChecklistItem) }
Though the definition of protocol is quite clear, it is kind of contract that should be conformed in order to be used. But here is the implementation of the function of the protocol in the body of the conforming class
func addItemViewController(_ controller: AddItemViewController,
didFinishAdding item: ChecklistItem) {
let newRowIndex = items.count
items.append(item)
let indexPath = IndexPath(row: newRowIndex, section: 0)
let indexPaths = [indexPath]
tableView.insertRows(at: indexPaths, with: .automatic)
dismiss(animated: true, completion: nil)
}
And there is no actual usage of controller argument, and what is didFinishAdding? As far as I understand, didFinishAdding is just an external name for the internal argument item. But how it works, how it could be understand from the body of the protocol that controller named AddItemViewController sends ChecklistItem to the conforming delegate, or is it some pre-defined function type?