I have an app and a walkthrough screen and I want to display the walkthrough screen if the user's open the app for first time, but I do it wrong. Should I put the code in the AppDelegate or in the ViewDidLoad inside my first screen. Here is the code I used:
super.viewDidLoad()
if UserDefaults.standard.bool(forKey: "isFirstLaunch") {
UserDefaults.standard.set(true, forKey: "isFirstLaunch")
UserDefaults.standard.synchronize()
}
let isFirstLaunch = UserDefaults.standard.value(forKey: "isFirstLaunch") as? Bool
if isFirstLaunch! {
let mainStoryboard = UIStoryboard(name: "ViewController", bundle: Bundle.main)
let vc : ViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
self.present(vc, animated: true, completion: nil)
}
and a picture of the error:
Any ides how to do it?