johnjay22113 johnjay22113 - 2 years ago 146
iOS Question

How to run code before initial view opens?

i want to run this code before the initial view controller even opens the view so the app knows where to redirect the user if the user is logged in. how can i do that? the code is here:

if let firstCheck = NSUserDefaults.standardUserDefaults().objectForKey("username"){
self.performSegueWithIdentifier("View1ToView2Segue", sender: nil)

i put the code after override func viewDidLoad() but it didnt work.

Answer Source

Unfortunately, you cannot do that. :( In this case, I would have a load image or something similar and have it fade away if the segue is not supposed to be performed. You would run this in the viewDidAppear method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download