0

I am trying to check if a textbox has no value.

When I do this:

if(userEmail?.isEmpty || userPassword?.isEmpty || userPasswordRepeat?.isEmpty)  

I get the following error enter image description here

I tried adding "?" before the ".isEmpty" but the error won't go away enter image description here

Any ideas?

Francesco Vadicamo
  • 5,522
  • 35
  • 29
Mathias Verhoeven
  • 927
  • 2
  • 10
  • 24
  • 1
    It's in the error message: Optional value not unwrapped. Use `!` to unwrap a value and read up on [optional values](http://stackoverflow.com/questions/24003642/what-is-an-optional-value-in-swift) – Arc676 Oct 10 '15 at 08:40
  • @EICaptain Is there a difference between `textfield.text` and `textfield.stringValue`? – Arc676 Oct 10 '15 at 08:43
  • @EICaptain I'm asking. I'm used to using `stringValue` – Arc676 Oct 10 '15 at 08:46
  • 1
    @Arc676 `stringValue` property is not a member of textfiled when your develop app for iPhone or iPad...is available in mac app – Bhavin Bhadani Oct 10 '15 at 08:49
  • This is a screenshot with the variables too. http://ge.tt/3NeaYbP2/v/0?c – Mathias Verhoeven Oct 10 '15 at 08:53

2 Answers2

1

Try this....

if txtEmail.text?.isEmpty == true || txtPassword.text?.isEmpty == true || txtRePassword.text?.isEmpty == true{
        print("true")
}
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
0

If interested also in positive case, the following is an alternative solution for Swift 2:

let email = self.txtEmail.text where !email.isEmpty, let password = self.txtPassword.text where !password.isEmpty {
    //all fields are not nil && not empty
}else{
    //some field is nil or empty
}
Francesco Vadicamo
  • 5,522
  • 35
  • 29