0

I'm trying to create multiple views in swiftui for signup user form. I want to display some information (phone number, password) and when he press a button (NEXT) a new page appear with date of birth (...) and at the end all is send to firebase for create the account.

But I'm a beginner in SWIFT (not in C# or python) and i don't find any tutorial or example to do this. I have a login page and a signup page with animation to go from one page to another, and the function to create an account with firebase, but i can't find how create multiple views in signup page and pass the information between this multiple views.

I have find this to pass information : https://stackoverflow.com/a/41623076 But i want to do this by the best way it can be. Thank you for your help !

Keal Mlj
  • 103
  • 1
  • 9
  • 1
    please read this. https://stackoverflow.com/help/how-to-ask . -This community is not about "opinions". There is no "best way". There are always different approaches. And if you are a SwiftUI beginner you should begin with tutorials...your link does not refer to SwiftUI ;) A SwiftuI Solution for your problem would be to work with @Published and environmentvariable.... – Chris Feb 18 '20 at 08:56
  • I would kindly suggest you to try some code and implement it before you ask directly. You are always welcome here on stack if you have doubts or errors but only when you try and implement the query . – Deven Nazare Feb 18 '20 at 09:51
  • @Chris thanks, but this is to have the best way with swiftUI, i think there is some function can do this but if not i have my idea. I create some .swift files with presentation like i want (firts name and surname,next date of birth ...) i create a int variable that take +1 when i press next or -1 when i press return and i display the view.swift i want and all the data are accessible to all file – Keal Mlj Feb 18 '20 at 10:29

1 Answers1

1

You need to follow Combine Framework(Reactive Programming)

Create a Observable Object

class UserAuth: ObservableObject {
    @Published var userLoggedIn: Bool = false
}

Where you create your scene delegate class add your environment object

func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    // Create the SwiftUI view that provides the window contents.
    let userAuth = UserAuth()
    let contentView = AppNavigationView().environmentObject(userAuth)
    // Use a UIHostingController as window root view controller.
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: contentView)
        self.window = window
        window.makeKeyAndVisible()
}

update the same environment object in your login class as bellow

struct LoginView: View {

    @EnvironmentObject var userAuth: UserAuth

    func callWebservicePerformLogin() {
       //update the user auth object which will send updates t
       self.userAuth.userLoggedIn = true
    }
}

Listener class

struct AppNavigationView: View {
    @EnvironmentObject var userAuth: UserAuth

    var body: some View {
        if !userAuth.userLoggedIn {
            return AnyView(LoginView())
        } else {
        return AnyView(PlayerList())
        }
    }
}