I make onboarding with UIPageViewController its work but when I run the App for Second time the Xib not working
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//////OnBoarding
let lunchbefor = UserDefaults.standard.bool(forKey: "haslunched")
self.window = UIWindow(frame: UIScreen.main.bounds)
let lunchstoryboard = UIStoryboard(name: "onboarding", bundle: nil)
let mainstoryboard = UIStoryboard(name: "Main", bundle: nil)
var vc: UIViewController
if lunchbefor{
window?.rootViewController = MainVC()
vc = mainstoryboard.instantiateInitialViewController()!
}else{
vc = lunchstoryboard.instantiateViewController(withIdentifier: "start")
}
UserDefaults.standard.set(true, forKey: "haslunched")
if lunchbefor == false{
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
}else{
window?.makeKeyAndVisible()
window?.rootViewController = MainVC()
}
return true
}
error:
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
on this line:
vc = mainstoryboard.instantiateInitialViewController()!