Building Apps with SwiftUI

Implementing Navigation and Finishing Off

Your browser needs to be JavaScript capable to view this video

Try reloading this page, or reviewing your browser settings

Autoplay:
View previous videoPrevious video

In this video segment, we set up navigation within the app once the user is authenticated to the dashboard view.

Keywords

  • navigation
  • swift navigation
  • swiftui
  • xcode
  • ios

About this video

Author(s)
Mehul Mohan
First online
22 August 2019
DOI
https://doi.org/10.1007/978-1-4842-5310-6_12
Online ISBN
978-1-4842-5310-6
Publisher
Apress
Copyright information
© Mehul Mohan 2019

Video Transcript

All right, guys, welcome back. And in this video, let’s just finally create that link. When we authenticated, actually authenticated, we are navigated away to the dashboard. So how we going to do that?

Well, right now, SwiftUI why does not perform any out of the box, programmatically, navigation support. But we can do a little bit of that stuff ourselves. So how do we do that? It’s– let me just first of all create a root view, which is going to conform to the view protocol. And this would be our body some view.

Now what I’m going to do is I’m going to throw in a wee stack first of all, and say that if manager.authenticated is true, then I’m going to return my dashboard, or actually the content view, right? Else, I’m going to return my login view, right? And I’m going to move this manager to right here. And because we don’t need this here, but we actually need this here, so what we’re going to do is we’re going to get this as a binding. Now I’m not making use of this as a state. I’m making use of this as a binding.

Now, why is that? Because I’m going to pass in my manager in the login view like that. Remember, in the text, are passing this as a binding. So SwiftUI receives this as a binding, not as a state variable. So once we have this as a binding, we can make use of this just like that.

And for this part, we can just get rid of the debug view because we don’t need it right now. And for the root, you type– what we have is this is some view, and for the manager part, if the manager is authenticated, we have content view. Otherwise, we have login view with the binding to manager. And the manager then calls the authentication API on check-in.

All right, so far seems good. Now if you go ahead and run the Play button, what is going to happen, eventually, is that the app is going to launch and we’re going to enter some credentials for the application. And let’s just see where it went wrong. So it says it’s missing manager for– OK. So now, we need a root view instead of the login view inside rc.delegate.swift file. So that should make it work now.

All right, so once we are here, what I’m going to do is write in the admin, and admin, and hit login. So once we do that, we’re going to see that it’s the correct login, and it does a correct login, and we get navigated away to the dashboard screen.

So yeah, that’s pretty much it for this series, and that will be all. I guess you can find the code for everything we have discussed so far in somewhere as a link here. And this application works great out of the box with the SwiftUI dark mode as well, so if you want to consider that as a thing, you can just go ahead and check that.

So yeah, you can hide the grid if you want. Honestly, I would just hide that if I were at your place. But anyway, see that you get a lot of customization out of the box with SwiftUI. So that will be all, and it was great having worked on this project, and I hope you had a good time working on this and enjoyed the process. And yeah, so that would be all for the series.