Hi forum members,
I am a beginner Swift programmer who is struggling to create my first prototype of SNS-type app. I am building an account creation page currently and I'm stacked at the stage to implement confirmation page for users to check if the information they input on the previous page is correct. I have now wrote the code below but it seems the code failed to display the user input on confirmation page. It seems the code stacked at the stage to pass information to Confirmation page.
import SwiftUI
struct AccountRegistrationView: View {
@State private var userName = ""
@State private var email = ""
@State private var pass = ""
var body: some View {
NavigationStack {
VStack() {
Text("Welcome to XXXXXXXXX!")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.mint)
.padding(10.0)
Text("Enter your user name, email address and password.")
.font(.body)
.multilineTextAlignment(.center)
.frame(width: 320.0, height: 50.0)
}
VStack {
TextField("User name", text: $userName)
.multilineTextAlignment(.center)
.padding(.all, 20.0)
.textFieldStyle(RoundedBorderTextFieldStyle())
TextField("Email address", text: $email)
.multilineTextAlignment(.center)
.padding(.all, 20.0)
.textFieldStyle(RoundedBorderTextFieldStyle())
TextField("Password", text: $pass)
.multilineTextAlignment(.center)
.padding(.all, 20.0)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
NavigationLink {
ConfirmationView()
} label: {
Label("Next", systemImage: "arrowshape.forward.fill")
.font(.body)
}
}
}
struct ConfirmationView: View {
let userInfo = AccountRegistrationView()
var body: some View {
Text("User name: \(userInfo.userName)")
.multilineTextAlignment(.center)
.padding(.all, 20.0)
Text("Email address: \(userInfo.email)")
.multilineTextAlignment(.center)
.padding(.all, 20.0)
Text("Password: \(userInfo.pass)")
.multilineTextAlignment(.center)
.padding(.all, 20.0)
}
}
struct AccountRegistrationView_Previews: PreviewProvider {
static var previews: some View {
AccountRegistrationView()
}
}
}
It would be much appreciated if you can point out which part of the code is causing the error and how to fix it.
Thank you so much for your support in advance!