I was working through a Ray Wenderlich tutorial and noticed that the author uses class extensions to hold delegate callbacks rather than having them be handled in the class itself i.e.:
delegate callbacks inside class extension:
extension LogsViewController : UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
...
}
}
as opposed to having it be contained within the class:
delegate callbacks inside class:
class LogsViewController : UITableViewController, UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
...
}
}
I found this strange and interesting at the same time. He has a file dedicated just to extensions on the LogsViewController class named "LogsViewControllerExtension.swift" and has a different extension for each delegate protocol: UITableViewDataSource, UISplitViewDelegate, etc i.e.:
multiple class extensions each w/ delegate callbacks inside its own file:
extension LogsViewController: UISplitViewControllerDelegate {
... callbacks
}
extension LogsViewController : UIPopoverPresentationControllerDelegate {
... callbacks
}
Why?
What advantages are there to doing this? I can see where it might be a little more readable to separate this out but at the same time it is a level of indirection. Are there OO principles that are supportive of or against doing this?