Reputation: 91
I have a load page in my application I created. I am trying to set up a tutorial. The load page will simple switch view controllers depending if the tutorial has been completed or not.
I would like to have the app perform the tutorial once when it is opened for the first time. I have created two segue. One that goes to the tutorial home screen and the other that will go to the screen every time the user opens the app after.
I have added the following code to the load page to determine if the tutroial is complete or not. The problem I am having is that my load page is doing nothing. Its not executing the code when it load. Here is the code:
import Foundation
import UIKit
class FrontPageViewController: UIViewController {
var isTutorialComplete = false;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if (isTutorialComplete == false) {
//Pushes to tutorial home page
self.performSegueWithIdentifier("ToTutorialHome", sender: nil)
}
else
{
//pushes to tech home page
self.performSegueWithIdentifier("ToTechHome", sender: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Upvotes: 1
Views: 96
Reputation: 5658
Store the bool in NSUserDefaults.
First time when you load the NSUserDefaults value will be false when he finish the tutorial and click done you have to set it as true and it's done
Do it like this
let settingdefaults = NSUserDefaults.standardUserDefaults()
var isTutorialComplete = settingdefaults.boolForKey("onboarding")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if (isTutorialComplete){
//pushes to tech home page
self.performSegueWithIdentifier("ToTechHome", sender: nil)
}
else {
//Pushes to tutorial home page
self.performSegueWithIdentifier("ToTutorialHome", sender: nil)
}
}
Once he finish the tutorial do like this
settingdefaults.setBool(true, forKey: "onboarding")
isTutorialComplete = settingdefaults.boolForKey("onboarding")
Upvotes: 2