Created
September 16, 2022 10:57
-
-
Save likil33/92039fd22f6c96d2e382e947dd8f8285 to your computer and use it in GitHub Desktop.
Root View controller swift
This file contains hidden or 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 | |
| // MARK: Switcher class | |
| enum RootVC:String { | |
| case LoginViewController, TabBarVC | |
| } | |
| class Switcher { | |
| static let shared = Switcher() | |
| private init() {} | |
| static func updateRootVC(_ rootVC:RootVC) { | |
| var navigationController = UINavigationController() | |
| if UserDefaults.standard.bool(forKey: "KLogin") == false { | |
| guard let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController else { | |
| return | |
| } | |
| navigationController = UINavigationController(rootViewController: rootVC) | |
| } else if rootVC == .TabBarVC { | |
| guard let rootVC = UIStoryboard.init(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "TabBarVC") as? TabBarVC else { | |
| return | |
| } | |
| navigationController = UINavigationController(rootViewController: rootVC) | |
| } | |
| UIApplication.shared.windows.first?.rootViewController = navigationController | |
| UIApplication.shared.windows.first?.makeKeyAndVisible() | |
| } | |
| func resetRoot() { | |
| var navigationController = UINavigationController() | |
| if UserDefaults.standard.bool(forKey: "KLogin") == true { | |
| guard let rootVC = UIStoryboard.init(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "TabBarVC") as? TabBarVC else { | |
| return | |
| } | |
| navigationController = UINavigationController(rootViewController: rootVC) | |
| }else{ | |
| guard let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController else { | |
| return | |
| } | |
| navigationController = UINavigationController(rootViewController: rootVC) | |
| } | |
| UIApplication.shared.windows.first?.rootViewController = navigationController | |
| UIApplication.shared.windows.first?.makeKeyAndVisible() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment