guichonator19
guichonator19

Reputation: 31

First time launch / segue swift

what i am trying to accomplish is once the app is launched it will check for first time use. if it is the first time use it will take you to a view controller to enter credentials, else it will take you to to the main menu of the app. this is what i have so far but every time i launch it will give me a blank page with the error message of "A segue must either have a performHandler or it must override -perform. " i have both segues linked on storyboard. can any one please steer me in the right direction.

    let defaults = UserDefaults.standard
    if defaults.string(forKey: "isAppAlreadyLaunchedOnce") != nil{
        print("first time")
        self.performSegue(withIdentifier: "toToken", sender: nil)
    }else{
        defaults.set(true, forKey: "isAppAlreadyLaunchedOne")
        defaults.synchronize()
        print("not first")
        self.performSegue(withIdentifier: "toMainMenu", sender: nil)
    }

Upvotes: 0

Views: 615

Answers (2)

Cyril
Cyril

Reputation: 2818

Your method is very confusing. The way I go about this problem is shown below.

override viewDidLoad() {
super.viewDidLoad

let checkForFirstTimeLaunch = Userdefaults.standard.string(forKey: "Flag")

if checkForFirstTimeLaunch == false {
print("First time launch")

//if user launches app for the first time, it will go here

} else {
//otherwise, it will go here

}

}

Upvotes: 0

0xNSHuman
0xNSHuman

Reputation: 648

If your segue type is set to be Custom in Storyboard — you have to subclass UIStoryboardSegue with your own logic in order for it to work.

class MySegue: UIStoryboardSegue {
    override func perform() {
        // your custom transition logic
    }
}

Otherwise just use one of the existing presets from iOS SDK.

Upvotes: 1

Related Questions