title: Swift generic enums for as TableView data source
body: <p>I want to create a UITableViewController that accepts an <code>enum</code> as it's data source.
  The thing is, I have quite a few <code>enums</code> that I want it to be able to handle.</p>
  
  <p>I created a protocol called <code>TableViewSelectable</code> and created some <code>enums</code> that conform to it like so:</p>
  
  <pre><code>protocol TableViewSelectable {
  
  }
  
  enum Genders: Int, TableViewSelectable {
      case male = 0, female
  
      static let allKeys = [male, female]
      static let allNames = [male.getName, female.getName]
  
      var getName: String {
          switch self {
          case .male:
              return "Male"
          case .female:
              return "Female"
          }
      }
  }
  
  enum Goals: Int, TableViewSelectable {
      case gainMuscleMass, getTrimFit, loseWeight
  
      static let allKeys = [gainMuscleMass, getTrimFit, loseWeight]
      static let allNames = [gainMuscleMass.getName, getTrimFit.getName, loseWeight.getName]
  
      var getName: String {
          switch self {
          case .gainMuscleMass:
              return "Gain muscle mass"
          case .getTrimFit:
              return "Get trim &amp; fit"
          case .loseWeight:
              return "Lose weight"
          }
      }
  }
  </code></pre>
  
  <p>And I have created an instance variable on my <code>UITableViewController</code> like so:</p>
  
  <pre><code>class ChoiceListTableViewController: UITableViewController {
  
      var data: TableViewSelectable?
  
  }
  </code></pre>
  
  <p>The problem is I have no idea how to go from here.
  What I want to have is the option to give that <code>UITableViewController</code> any <code>enum</code> that conforms to <code>TableViewSelectable</code> in order to use as its data source.</p>
  
  <p>I want to access it on the <code>UITableViewController</code> like this:</p>
  
  <pre><code>final class ChoiceListTableViewController: UITableViewController {
  
      var data: TableViewSelectable?
  
  
      // MARK: Lifecycle
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.clearsSelectionOnViewWillAppear = false
      }
  
  }
  
  // MARK: Table View Data Source &amp; Delegate
  
  extension ChoiceListTableViewController {
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
  
          return 1
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          return data.allKeys.count
      }
  
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let cell = tableView.dequeueReusableCell(withIdentifier: "ChoiceTableViewCell", for: indexPath)
  
          cell.textLabel?.text = data.allNames[indexPath.row]
  
          return cell
      }
  
  }
  </code></pre>
  
  <p>Help please? :)</p>