Programmatically navigate to new view in SwiftUI

后端 未结 6 507
梦如初夏
梦如初夏 2020-12-01 20:52

Descriptive example:

login screen, user taps \"Login\" button, request is performed, UI shows waiting indicator, then after successful response I\'d like to automati

6条回答
  •  再見小時候
    2020-12-01 21:35

    For future reference, as a number of users have reported getting the error "Function declares an opaque return type", to implement the above code from @MoRezaFarahani requires the following syntax:

    struct ContentView: View {
    
        @EnvironmentObject var userAuth: UserAuth 
    
        var body: some View {
            if !userAuth.isLoggedin {
                return AnyView(LoginView())
            } else {
                return AnyView(NextView())
            }
    
        }
    }
    

    This is working with Xcode 11.4 and Swift 5

提交回复
热议问题