Skip to content

Instantly share code, notes, and snippets.

@smosko
Last active April 23, 2019 12:57
Show Gist options
  • Save smosko/3e73555bfee6a86b17a3595a08ce57cc to your computer and use it in GitHub Desktop.
Save smosko/3e73555bfee6a86b17a3595a08ce57cc to your computer and use it in GitHub Desktop.
Bubble up events from child ViewControllers using the UIResponder chain
// LocationPickerViewController.swift
class LocationPickerViewController: UITableViewController {
...
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
didSelectLocation(locations[indexPath.row])
}
}
extension UIResponder {
@objc func didSelectLocation(_ location: Location) {
next?.didSelectLocation(location)
}
}
// AppFlowController.swift
class AppFlowController: UIViewController {
// LocationPickerViewController is contained in childViewControllers hierarchy
...
override func didSelectLocation(_ location: Location) {
// handle event
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment