title: How to pass the date picker (or just the date) to show the date on textfield in Swift?
body: <p>I want show a date picker view on keyboard. I am doing this using UITextField extension.</p>
  
  <p>My code:</p>
  
  <pre><code>extension UITextField {
  
  //... other functions
  
  func showDatePicker(){
      let datePicker = UIDatePicker()
      datePicker.datePickerMode = .date
  
      let toolbar = UIToolbar();
      toolbar.sizeToFit()
  
      let doneButton = UIBarButtonItem(title: "Pronto", style: UIBarButtonItemStyle.plain, target: self, action: #selector(UITextField.doneDatePicker(_:)))
      let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
      let cancelButton = UIBarButtonItem(title: "Cancelar", style: UIBarButtonItemStyle.plain, target: self, action: #selector(UITextField.donePicker))
      toolbar.setItems([cancelButton,spaceButton,doneButton], animated: false)
  
      self.inputAccessoryView = toolbar
  
      self.inputView = datePicker
  
  }
  
  @objc func doneDatePicker(_ datePicker: UIDatePicker){
  
      let formatter = DateFormatter()
      formatter.dateFormat = "dd/MM/yyyy"
      self.text = formatter.string(from: datePicker.date)
      self.endEditing(true)
  }
  }
  </code></pre>
  
  <p>My problem is when I tap "Pronto" button and the function doneDatePicker is executed. I need pass the UIDatePicker (or just the date) to show the date on textfield but I get this error:</p>
  
  <pre><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem date]: unrecognized selector sent to instance 0x103488850'
  </code></pre>
  
  <p>How can I solve this?</p>