Is there a way to check strings for nil and \"\" in Swift? In Rails, I can use blank() to check.
I currently have this, but i
helpful when getting value from UITextField and checking for nil & empty string
@IBOutlet weak var myTextField: UITextField!
Heres your function (when you tap on a button) that gets string from UITextField and does some other stuff
@IBAction func getStringFrom_myTextField(_ sender: Any) {
guard let string = myTextField.text, !(myTextField.text?.isEmpty)! else { return }
//use "string" to do your stuff.
}
This will take care of nil value as well as empty string.
It worked perfectly well for me.