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      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.