title: How do I transfer the datasource for a viewTable from another swift file?
body: <p>I know this may sound very stupid, i've been trying for hours but couldn't figure out how. How do I load the titles to the tableView in this scenario? </p>
  
  <p>I know there is an easy method where you can declare an array in the ViewController.swift file and make the delegate and datasource = self like this:</p>
  
  <pre><code>self.drugsTableView.dataSource = self
  self.drugsTableView.delegate = self
  </code></pre>
  
  <p>But in this case i would like to get the tableView datasource from another swift file, here is how my scenario is going:</p>
  
  <p>In the project navigator i have the following files:</p>
  
  <p><strong>1. ViewController.swift</strong> </p>
  
  <p><strong>2. DrugsLibrary.swift</strong></p>
  
  <p><strong>3. DrugList.swift</strong></p>
  
  <blockquote>
    <p><strong>ViewController.swift</strong></p>
  </blockquote>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  
  @IBOutlet weak var drugsTableView: UITableView!
  
  var drugList: DrugsLibraryStruct?
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.drugsTableView.dataSource = self
      self.drugsTableView.delegate = self
      self.navigationItem.title = "Titles"
  
  }
  
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return DrugsLibraryStruct().drugsLibraryDictionary.count
  }
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"test")
      return cell
  }
  </code></pre>
  
  <blockquote>
    <p><strong>DrugsLibrary.swift</strong>:</p>
  </blockquote>
  
  <pre><code>import Foundation
  
  struct DrugsLibraryStruct {
  
  let drugsLibraryDictionary = [
      [
          "name": "Drug A",
          "subtitle": "Drug A subtitle!",
          "icon": "drugA.pdf"
  
      ],
      [
          "name": "Drug B",
          "subtitle": "Drug B subtitle",
          "icon": "drugb.pdf"
      ]
  ]
  </code></pre>
  
  <p>}</p>
  
  <blockquote>
    <p><strong>DrugList.swift</strong>:</p>
  </blockquote>
  
  <pre><code>import Foundation
  import UIKit
  
  struct DrugListStruct {
  
  var name: String?
  var subtitle: String?
  var icon: UIImage?
  
  init(index: Int) {
  
      let drugsLibrary = DrugsLibraryStruct().drugsLibraryDictionary
      let drugListDictionary = drugsLibrary[index]
  
      name = drugListDictionary["name"] as String!
      subtitle = drugListDictionary["subtitle"] as String!
  
      let iconName = drugListDictionary["icon"] as String!
      icon = UIImage(named: iconName)
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the <a href="https://www.dropbox.com/s/okfnk7z4hafc2qb/transfer2.zip?dl=0" rel="nofollow">source code</a> on Dropbox</p>
  
  <p>I would really appreciate your hints or help.</p>
  
  <p>Thank you!</p>