UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Navigating From "NavigationViews" to "TabViews"

Forums > SwiftUI

I don't really have code to share, but the idea and question is pretty simple, I just cannot seem to find the right way to do it.

I have a SaaS-type application where a user signs up, receives a Web Token which goes into the UserDefaults. Once this is complete, and that token is present, I want to take the user to a TabView with the main menu stuff and they can begin using the app.

What's the best way to essentially break away from the NavigationView flow where a user creates their account, and then drop them into the TabView where they can begin using the app.

I tried:

On the final NavigationView screen, the user finishes adding all their account information, the token comes back and gets stored, and then I render a "Continue" button. The action on this button calls MainTabView() to try and kick-off the new flow of using the app's main features.

All that happens is I receive this error:

Result of 'MainTabView' initializer is unused

Any insights?

3      

Hi Thomas,

Have you tried a .fullScreenCover. This covers the TabView.

here some dummy code

struct ContentView: View {
    @AppStorage("token") var noToken = true

    var body: some View {
        TabView {
            TabOne()
                .tabItem {
                    Text("One")
                }
            TabTwo()
                .tabItem {
                    Text("Two")
                }
        }
        .fullScreenCover(isPresented: $noToken) {
            TokenView(noToken: $noToken)
        }
    }
}

and TokenView

struct TokenView: View {
    @AppStorage("tokenName") var tokenName = ""
    @Binding var noToken: Bool

    var body: some View {
        VStack {
            TextField("Enter Token", text: $tokenName)
                .padding()

            Button("Submit") {
                noToken = false
            }
        }
    }
}

PS you should not store token in UserDefaults/@AppStorage etc. You should really store it in KeyChain as this is encrypted.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.