Last active
March 11, 2024 20:16
-
-
Save Myrrel/12b944e6b23dd44abaf70b152d614f62 to your computer and use it in GitHub Desktop.
UIKit + Coordinator
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
import Foundation | |
import UIKit | |
protocol Coordinator { | |
var viewController: UIViewController? {get} | |
var navigationController: UINavigationController? {get} | |
func start() | |
} | |
extension Coordinator { | |
var viewController: UIViewController? {nil} | |
var navigationController: UINavigationController? {nil} | |
} |
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
import Foundation | |
import UIKit | |
class MainCoordinator: Coordinator { | |
var navigationController: UINavigationController? | |
init(navigationController: UINavigationController? = nil) { | |
self.navigationController = navigationController | |
} | |
func start() { | |
let vc = ViewController() | |
navigationController?.pushViewController(vc, animated: true) | |
} | |
func showDetail(item: Model) { | |
let vc = DetailViewController(item: item) | |
navigationController?.pushViewController(vc, animated: true) | |
} | |
} |
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
import UIKit | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
var mainCoordinator: MainCoordinator? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
guard let windowScene = (scene as? UIWindowScene) else { return } | |
window = UIWindow(windowScene: windowScene) | |
let navigation = UINavigationController() | |
mainCoordinator = MainCoordinator(navigationController: navigation) | |
window?.rootViewController = navigation | |
window?.makeKeyAndVisible() | |
mainCoordinator?.start() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment