title: Passing data from a UIPickerView to a UIViewController in Swift 5
body: <p>I'm currently trying to build a simple app in Swift 5 that has a main <code>UIViewController</code>:</p>
  
  <pre><code>class TheList: UIViewController{
  
      @IBOutlet var tableView: UITableView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          tableView.delegate = self
          tableView.dataSource = self
      }
      (...)
  }
  </code></pre>
  
  <p>The <code>UIViewController</code> has an Extension that utilises the <code>UITableViewDataSource</code> and <code>UITableViewDelegate</code> protocols.</p>
  
  <pre><code>extension TheList: UITableViewDelegate, UITableViewDataSource{
  
  (...)
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          switch indexPath.row {
          case 0:
              let cell = tableView.dequeueReusableCell(withIdentifier: "titleViewCell")!
              return cell
  
  (...)
  
  }
  </code></pre>
  
  <p>It populates the table with certain dynamic <code>UITableViewCells</code>, that are their own, separate classes. Here's an example of one:</p>
  
  <pre><code>class AmtTableViewCell: UITableViewCell{
  
      @IBOutlet var hoursPickerView: UIPickerView!
  
      override func awakeFromNib() {
          super.awakeFromNib()
          populate()
          hoursPickerView.delegate = self
          hoursPickerView.dataSource = self
      }
  
  (...)
  }
  
  extension AmtTableViewCell: UIPickerViewDelegate, UIPickerViewDataSource{
      func numberOfComponents(in pickerView: UIPickerView) -&gt; Int {
          return 1
      }
  
      func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
          return pickerData.count
      }
  
      func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String? {
          return String(pickerData[row])
      }
  
  
  }
  </code></pre>
  
  <p>As you can see, that <code>UITableViewCell</code> has an outlet of a <code>UIPickerView</code>. I would like to somehow pass the data from this class's <code>UIPickerView</code> to my <code>UIViewController</code>, so that I can parse it further there. I've tried to create a method to do so and then call it in my View Controller, but from I understood I had to instantiate it first, which kills the point, as I would like to get the value from the instance the user sees on their screen.</p>
  
  <p>I have also tried to create an outlet for the Picker in my View Controller and then set up its Delegate and Data Source as the <code>AmtTableViewCell</code> class instead of <code>self</code> but I've learned I can't put that <code>UIPickerView</code> in my <code>UIViewController</code>.</p>
  
  <p>Any help is appreciated.</p>