Reputation: 135
I'm trying to run a block of code when the application first starts if the user hasn't setup the application yet. Currently, the code checks stored UserDefaults via another method (for cleanliness) to see if the application has been setup. That shouldn't matter in this case however, as I hard coded the software to think that the application has not yet been setup. I then have the application check to see if it has been setup (referencing the hard code) within the viewDidAppear function for the ViewController. Upon seeing that it hasn't been setup, it then calls a method that asks to segue to a SetupViewController. For some reason though, it is calling the segue twice. So once the segue is performed and I see the other view, it seems to try and run it again and then throws an exception. Below is my code and my log's output. What in my code is incorrect, or what am I missing in the logic of my code? I also checked and made sure the segue does have the proper identifier in the Main.storyboard. Thanks in advance guys!
ViewDidAppear code:
/*
ViewDidAppear - If the view has appeared after loading we will run some code to check the state of the app.
*/
override func viewDidAppear(_ animated: Bool) {
// If the application hasn't been setup and it believes it isn't setup run setup.
if(checkIfSetup() != true && hasSetup == false)
{
print("attempted run")
runSetup()
}
// If the application has been setup and believes it has been setup, load view.
else if(checkIfSetup() == true && hasSetup == true)
{
loadApp()
}
}
Method calling for segue called "RunSetup:"
/*
RunSetup - Runs the setup for the application environment.
*/
func runSetup()
{
print("Running setup for AppName") // Notify the log that you are running the App's setup.
// ## Start by clearing all possibly stored data. ##
//REALM - Destroy Database if it exists
try! realm.write {
realm.deleteAll()
}
//Begin setting up the environment
self.performSegue(withIdentifier: "dismissAndCreate", sender: self)
print("tryingSegue")
}
Log Output:
attempted run
Running setup for AppName
tryingSegue
attempted run
Running setup for AppName
2017-04-03 17:12:57.404 AppName[22109:3226052] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<AppName.SetupAppViewController: 0x7ffc97824400>) has no segue with identifier 'dismissAndCreate''
*First Throw Stack is then listed*
Upvotes: 0
Views: 1151
Reputation: 135
Solution came in a very simply way. I forgot to create a viewDidAppear or even viewDidLoad function in the SetupViewController. This solved the problem.
Upvotes: 1