title: alert iOS swift
body: <p>When I test for bad data in a text field and try  to show an alert for missing or bad data the alert does not display. But I can get an alert to display in the viewDidLoad function</p>
  
  <p>Here is the code</p>
  
  <pre><code> import UIKit
   import CoreData
  
  class SellViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate  {
   @IBOutlet weak var customer: UITextField!
  @IBOutlet weak var bales: UITextField!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let alert = UIAlertController(title: "Hey", message: "@ SellViewController viewDidLoad ", preferredStyle: UIAlertControllerStyle.Alert)
      alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
      self.presentViewController(alert, animated: true, completion: nil)
  
  func checkDataInput(){
  
      print("checking data input customer.text  \(customer.text)")
      print("checking data input bales.text \(bales.text)")
  
      if (customer.text!.isEmpty) {
          customer.text = "REQUIRED"
          missingCustomer()
      }
  if (bales.text!.isEmpty){
          availableAlert()
      }else{
          newQuantity = Int(bales.text!)!
       }
  
   func availableAlert() {
      print(" at availableAlert")
  
      let alert = UIAlertController(title: "Hey", message: "@ SellViewController func missingValues ", preferredStyle: UIAlertControllerStyle.Alert)
      alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
      self.presentViewController(alert, animated: true, completion: nil)
  
  
  func missingCustomer() {
      print(" at missingCustomer")
      let alert = UIAlertController(title: "Hey", message: "@ SellViewController func missingCustomer ", preferredStyle: UIAlertControllerStyle.Alert)
      alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
      self.presentViewController(alert, animated: true, completion: nil)
      }
  </code></pre>
  
  <p>This displays alert at viewDidLoad but no alert when I have missing data. The print statements when I have missing data return as.</p>
  
  <p>checking data input customer.text  Optional("")<br>
  checking data input bales.text Optional("")<br>
   at missingCustomer<br>
   at availableAlert<br>
  fatal error: unexpectedly found nil while unwrapping an Optional value  </p>
  
  <p>The fatal error happens because the user is not able to correct their response when they get the alert.</p>
  
  <p>What am I doing wrong? Shouldn't the alert display immediately when my 
  missingData functions are  triggered and the be able to correct their entries?</p>