I got fatal error While using guard let. Here's the error:
Initializer for conditional binding must have Optional type not 'String'
Below my code which i have used:
@IBAction func signUpButtonPressed(sender: UIButton) {
guard let email = emailTextField.text! where emailTextField.text!.characters.count > 0 else {
// alert
return
}
guard let password = passwordTextField.text! where passwordTextField.text!.characters.count > 0 else {
// alert
return
}
self.registerUserAsync(email, password: password)
}
You should be very carefull with optionals. Using
!
you tell to Swift compiler that you can guarantee that the value is exists. Try to do it like this:More about optionals you can find here https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309