The better approach would be to get existing storyboard instance from window's rootViewController
if not available then create a new instance.
let storyboard = self.window?.rootViewController?.storyboard ?? UIStoryboard.init(name: "Main", bundle: nil)
Also using globally accessible helper functions like these can be a good idea provided that you pass the already active storyboard as parameter.
class Helper {
static func getLoginVC(storyboard: UIStoryboard) -> LoginVC {
return storyboard.instantiateViewController(withIdentifier: String(describing: LoginVC.self)) as! LoginVC
}
}
you can pass the active storyboard instance from a controller like this -
let loginVC = Helper.getLoginVC(storyboard: self.storyboard)
In case you are trying to access storyboard from appDelegate or sceneDelegate you can use -
let storyboard = self.window?.rootViewController?.storyboard ?? UIStoryboard.init(name: "Main", bundle: nil)
let loginVC = Helper.getLoginVC(storyboard: storyboard)
let navigationController = UINavigationController.init(rootViewController: loginVC)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
self.storyboard
– DioeciousUIStoryboard *sb = [[self.window rootViewController] storyboard];
– Depilate