Question on cleaning up code/best practices

I am trying to keep my code clean while recreating a project I started a couple years ago. I have posted some of the code below and wondering if its possible to put the date picker in a different swift file like Chris did on the photo app.

I have tested it and appears to be working like it is suppose too, just trying to clean things up.

class DetailViewController: UIViewController {
    @IBOutlet var startDateTextField: UITextField!
    @IBOutlet var endDateTextField: UITextField!

    // Date Picker
    fileprivate var datePicker: UIDatePicker!
    fileprivate var currentTextFieldResponder = TextField.startDate
    fileprivate let dateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = .short
        return formatter
    override func viewDidLoad() {

        let tapRecognizer = UITapGestureRecognizer()
        tapRecognizer.addTarget(self, action: #selector(DetailViewController.didTapView))
        // Done Button
        // Date Picker base configuration
        datePicker = UIDatePicker()
        datePicker.datePickerMode = .date
        datePicker.addTarget(self, action: #selector(datePickerValueChanged(sender:)), for: .valueChanged)
        // TextField configuration
        startDateTextField.inputView = datePicker
        startDateTextField.tag = 0
        startDateTextField.delegate = self
        endDateTextField.inputView = datePicker
        endDateTextField.tag = 1
        endDateTextField.delegate = self
    // Date Picker Actions
    @objc func datePickerValueChanged(sender: UIDatePicker) {
        let selectedDateText = dateFormatter.string(from:
        switch currentTextFieldResponder {
        case .startDate:
            startDateTextField.text = selectedDateText
        case .endDate:
            endDateTextField.text = selectedDateText
    // Date Picker
    fileprivate enum TextField: Int {
        case startDate
        case endDate

extension DetailViewController: UITextFieldDelegate {
    // Just after a text object becomes first responder
    func textFieldDidBeginEditing(_ textField: UITextField) {
        // Update current text responder and rest datePicker's date
        currentTextFieldResponder = TextField(rawValue: textField.tag)!
        if  let dateText = textField.text,
            let date = dateText) {
   = date
    // Hide keyboard when user touches outside keyboard
    @objc func didTapView() {
    // Done Button on Numberpad
    func addDoneButtonOnKeyboard() {
        let doneToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
        doneToolbar.barStyle = UIBarStyle.default
        let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
        let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: self, action: #selector(doneButtonAction))
        var items = [UIBarButtonItem]()
        doneToolbar.items = items
        self.startDateTextField.inputAccessoryView = doneToolbar
        self.endDateTextField.inputAccessoryView = doneToolbar
    @objc func doneButtonAction() {