Swift Programming.
Add conditions to code below:
1.) Checks to see if both text fields are empty and if both are, prints out an error for the user
2.) Checks, if either one of the text fields are empty, also prints out an error for the user
--------------------------------------------------------------------------------------------------------------------------
@IBOutlet weak var addRouting: UITextField! //outlet for the
routing textfield
@IBOutlet weak var addAccount: UITextField!
//outlet for the account textfield
@IBAction func saveBankAccount(_ sender: Any) {
//button action
if addRouting.text!
.isEmpty{ //check for the empty routing
let alertControl = UIAlertController(title: "ERROR!", message:
"Enter Rounting", preferredStyle: .alert)
alertControl.addAction(UIAlertAction(title: "OK", style: .default,
handler: nil))
self.present(alertControl, animated: false)
}
else if
addAccount.text!.isEmpty{ //check for the empty account
let alertControl = UIAlertController(title: "ERROR!", message:
"Enter Account", preferredStyle: .alert)
alertControl.addAction(UIAlertAction(title: "OK", style: .default,
handler: nil))
self.present(alertControl, animated: false)
}
}
Below is the solution:
@IBOutlet weak var addRouting: UITextField!
@IBOutlet weak var addAccount:
UITextField!
@IBAction func alertBox(_ sender: Any) {
if addRouting.text!
.isEmpty && addAccount.text! .isEmpty{ //check for both
textbox empty
let alertControl = UIAlertController(title: "ERROR!", message:
"Enter Account and Routing", preferredStyle: .alert)
alertControl.addAction(UIAlertAction(title: "OK", style: .default,
handler: nil))
self.present(alertControl, animated: false)
}
else if
addAccount.text!.isEmpty{ //check for the empty account
let alertControl = UIAlertController(title: "ERROR!", message:
"Enter Account", preferredStyle: .alert)
alertControl.addAction(UIAlertAction(title: "OK", style: .default,
handler: nil))
self.present(alertControl, animated: false)
}
else if addRouting.text!
.isEmpty{ //check for the empty routing
let alertControl = UIAlertController(title: "ERROR!", message:
"Enter Rounting", preferredStyle: .alert)
alertControl.addAction(UIAlertAction(title: "OK", style: .default,
handler: nil))
self.present(alertControl, animated: false)
}
}

Swift Programming. Add conditions to code below: 1.) Checks to see if both text fields are...