devxoul / URLNavigator

⛵️ Elegant URL Routing for Swift
MIT License
3.23k stars 297 forks source link

How to pop an viewController? #96

Open qiushuitian opened 6 years ago

qiushuitian commented 6 years ago

hello, I implement the push like this in my viewModel:

let context = ["merch":merch]
DJNavigator.share.push("myApp://roomList/",context:context)

And In the roomListViewController I want pop to current viewController when I click the back button. But I have to write the code in the viewController (not in the viewModel) use origin pop:

self.navigationController?.popViewController(animated: true)

Can I do it using the URLNavigator so that I can write all view navigtion logic in viewModel ?

devxoul commented 6 years ago

URLNavigator doesn't support popping view controllers. If it is needed, you can still make an extension.

thepinyo commented 6 years ago

@devxoul How?

devxoul commented 6 years ago

@thepinyo Like this:

extension Navigator {
  func pop(animated: Bool = true) {
    UIViewController.topMost?.navigationController?.popViewController(animated: animated)
  }
}