Rovi Fauzan Akbar
Rovi Fauzan Akbar

Reputation: 3

how make statement if in xcode to change value

@State var password: String = ""
@State var passwordConfirm: String = ""
@State private var buttonDisabled = true


  if password == passwordConfirm{
                       self.buttonDisabled = false
                   }else{
                       self.buttonDisabled = true
                   }

i want change value buttonDisabled with condition if,when password and passwordConfirm same, pls help me

Upvotes: 0

Views: 33

Answers (1)

sfung3
sfung3

Reputation: 2377

You can achieve this by disabling the button when password == passwordConfirm.

I created two TextFields to demonstrate what you want but would suggest you using SecureField for passwords.

struct ContentView: View {
    @State var password: String = ""
    @State var passwordConfirm: String = ""

    var body: some View {
        VStack {
            TextField("Password", text: $password)
            TextField("Confirm password", text: $passwordConfirm)

            Button(action: {
                print(self.password == self.passwordConfirm)
            }) {
                Text("Create Account")
            }.disabled(password == passwordConfirm)
        }
    }
}

Upvotes: 1

Related Questions