Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Michael Lee
2,855 PointsMaking a view controller the root view controller in the app delegate file (Swift)
If I wanted to make a view controller, say logInViewController, the root view controller in Objective-C, I would:
Import the view controller, then type out the following lines of code:
LogInViewController *vc = [[LogInViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = navigationController;
So how would I do this in Swift?
1 Answer
Michael Hulet
47,913 PointsThe equivalent syntax in Swift would look like this:
let vc = LoginViewController()
let navigationController = UINavigationController(rootViewController: vc)
window.rootViewController = navigationController
Michael Lee
2,855 PointsMichael Lee
2,855 PointsThanks!
Michael Lee
2,855 PointsMichael Lee
2,855 PointsHey, I've done it as such:
However, ViewController still doesn't pop up when I first launch the app, instead getting a plain white screen due to this line of code:
self.window!.backgroundColor = UIColor.whiteColor()When deleted, the screen turns to black.
I don't think that the storyboard is set in the info.plist and there's no storyboard file.
Is there any line of code I need to add?
Thanks!