Checking if text fields are empty cause error in Swift 2
问题 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 I tried adding "?" before the ".isEmpty" but the error won't go away Any ideas? 回答1: Try this.... if txtEmail.text?.isEmpty == true || txtPassword.text?.isEmpty == true || txtRePassword.text?.isEmpty == true{ print("true") } 回答2: If interested also in positive case, the following is an alternative solution for Swift 2 : let