Created
February 23, 2018 14:21
-
-
Save Blightwidow/81194517bc717b09201bb913e5870543 to your computer and use it in GitHub Desktop.
MVVM Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Router { | |
func navigate( | |
to route: Routes, | |
_ parameters: Any?... | |
) | |
} | |
enum Routes: String { | |
case date | |
case home | |
} | |
import UIKit | |
class DateRouter: Router { | |
weak var view: UIViewController? | |
func navigate(to route: Routes, _ parameters: Any?...) { | |
guard let context = view else { return } | |
switch route { | |
case .home: | |
DispatchQueue.main.async { | |
let destinationVC = viewController(for: route.rawValue) | |
context.present(destinationVC, animated: true, completion: nil) | |
} | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment