Sunday, May 12, 2024
HomeiOS Developmentios - Making this SwiftUI App SignIn/Register appropriate

ios – Making this SwiftUI App SignIn/Register appropriate


import SwiftUI

struct SigninView: View {
    @State personal var isLoggedin = false
    @State personal var showRegistration = false
    @State personal var electronic mail = ""
    @State personal var password = ""
    @State personal var confirmPassword = ""
    @State personal var errorMessage = ""
    @State personal var navigateToDataInputView = false
    
    var physique: some View {
        NavigationView {
            VStack {
                if isLoggedin {
                    Textual content("Welcome, you are logged in!")
                    Button("Logout") {
                        self.isLoggedin = false
                    }
                    .padding()
                    if navigateToDataInputView {
                        NavigationLink(
                            vacation spot: DataInputView(),
                            isActive: $navigateToDataInputView,
                            label: {
                                EmptyView()
                            })
                    } else {
                        Button("Log in") {
                            self.navigateToDataInputView = true
                        }
                        .padding()
                    }
                } else {
                    if showRegistration {
                        VStack {
                            TextField("E mail", textual content: $electronic mail)
                                .padding(10)
                                .overlay {
                                    RoundedRectangle(cornerRadius: 10)
                                        .stroke(Shade.grey, lineWidth: 2)
                                }
                                .padding(.horizontal)
                            SecureField("Password", textual content: $password)
                                .padding(10)
                                .overlay {
                                    RoundedRectangle(cornerRadius: 10)
                                        .stroke(Shade.grey, lineWidth: 2)
                                }
                                .padding(.horizontal)
                            SecureField("Affirm Password", textual content: $confirmPassword)
                                .padding(10)
                                .overlay {
                                    RoundedRectangle(cornerRadius: 10)
                                        .stroke(Shade.grey, lineWidth: 2)
                                }
                                .padding(.horizontal)
                            Textual content(errorMessage)
                                .foregroundColor(.purple)
                            Button("Register") {
                                self.register()
                            }
                            Button("Again to Login") {
                                self.showRegistration = false
                                self.errorMessage = ""
                            }
                        }
                    } else {
                        VStack {
                            Button("Login") {
                                self.isLoggedin = true // For demo objective, simply set it to true instantly
                            }
                            .padding()
                            .foregroundColor(.white)
                            .background(Shade.blue)
                            .cornerRadius(10)
                            .padding()
                        }
                        Button("Register") {
                            self.showRegistration = true
                        }
                        .padding()
                    }
                }
            }
        }
    }
    
    personal func register() {
        // examine if passwords match
        if password != confirmPassword {
           
      
        isLoggedin = false
    }
}

struct DataInputView: View {
    var physique: some View {
        Textual content("Information Enter View")
    }
}

That is tbe starter code for the siwftui app im engaged on. On this app, youll be requested whether or not you wish to sign up or register. In the event you choose register, you get taken to a RegisterView web page after which create an account, with that data you click on again and get taken to the SignInView the place you now sign up with the main points you entered in earlier than on the register web page.

The register button would not work in any respect and it would not recieve any of the code. AI use has been fairly useful somewhat, Im utilizing blackbox b/c chatgpt isn’t recieving the code too effectively. I simply need the information to be saved with out having to do any backend work. This mission is tremendous simple and this half is meant to be the straightforward half



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments