Skip to content

Instantly share code, notes, and snippets.

@AvatarHurden
Created August 22, 2018 14:27
Show Gist options
  • Save AvatarHurden/9603d5c21a97a315c53235fa133558a2 to your computer and use it in GitHub Desktop.
Save AvatarHurden/9603d5c21a97a315c53235fa133558a2 to your computer and use it in GitHub Desktop.
PoppableVC
protocol Bindable {
associatedtype ViewModel
var viewModel: ViewModel! { get set }
func bindToViewModel()
}
protocol PoppableVC {
associatedtype Parent
}
protocol PoppableVM {
var action: CocoaAction { get }
}
extension UINavigationControllerDelegate where Self: UIViewController, Self: Bindable & PoppableVC, Self.ViewModel: PoppableVM {
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if viewController is Self.Parent {
self.viewModel.action.execute(())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment