John Doe
John Doe

Reputation: 521

Swift sets rootViewController in AppDelegate with delay

I want to set initial ViewController in AppDelegate. As:

 if jsonResult["result"]!.intValue == 1 {
     let entryPoint: UITabBarController = mainStoryboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
     self.window?.rootViewController = entryPoint
} else {
     let entryPoint: WelcomeController = mainStoryboard.instantiateViewControllerWithIdentifier("WelcomeController") as! WelcomeController
     self.window?.rootViewController = entryPoint
}

it works, but at first it opens the view controller which I set as initial in my storyboard and just later it switches programmatically.

So, how can I switch my controller directly without showing my first controller? What I do wrong?

Upvotes: 1

Views: 728

Answers (1)

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

In addition to galois's comment:

...and what happens if there is no result due to a completed request with an error? Force-unwrapping the result with ! would crash your app. You should look into Grand Central Dispatch calls. Start an asynchronous call to get your JSON with a callback on the main thread to update your UI upon completion and let your UI load into some "waiting" state directly while it waits in the background for the JSON.

Upvotes: 3

Related Questions