title: How do I segue from a tableviewcell and pass different data from each cell to the next tableview?
body: <p>I'm trying to practice making list apps with models by making a class to represent each list item. I have a Category class which contains three properties - two strings and one array of strings. Here is the class:</p>
  
  <pre><code>class Category {
  
     var name: String
     var emoji: String
     var topics: [String]
     // (the getCategories method listed below goes here) //  
  
   init(name: String, emoji: String, topics: [String]) {
      self.name = name
      self.emoji = emoji
      self.topics = topics 
   }
  </code></pre>
  
  <p>In my Category class I have a method to assign values to the categories so I can keep them out of the view controller. This method is listed below:</p>
  
  <pre><code>class func getCategories() -&gt; [Category]
  {
     let categories = 
      [Category(name:"cat", emoji:"", topics:["paws","tails", "fur", "pussyfoot","purr", "kitten", "meow"]), 
      Category(name: "car", emoji: "", topics: ["motor", "speed", "shift", "wheel", "tire"])
      ]
   return categories
  }
  </code></pre>
  
  <p>I have two UITableViewControllers - CategoryTableViewController and TopicsTableViewController; I want the user to be able to tap a category cell in the CategoryTableViewController and then be taken to the TopicsTableViewController where the topics for the category they selected are displayed in a tableview.  </p>
  
  <p>So far I am able to get the cell to segue to the TopicsTableViewController but it displays the same topics no matter which category I select.  Here is how I have my didSelectRowAtIndexPath and prepareForSegue set up in the CategoriesTableViewController... </p>
  
  <pre><code>override func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath)  {
          let indexPath = tableView.indexPathForSelectedRow
          let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as  UITableViewCell!
  }
  
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      if (segue.identifier == "fromCategorySegue") {
          let vc = segue.destinationViewController as!  TopicsTableViewController
          vc.categories = categories
      }
  }
  </code></pre>
  
  <p>It displays the first category (cat) topics on the TopicsTableViewController even if I select the second category (car).  </p>
  
  <p>In case it is helpful here is a snippet of some of my code in the TopicsTableViewController...</p>
  
  <pre><code>override func tableView(tableView: UITableView, cellForRowAtIndexPath       indexPath: NSIndexPath) -&gt; UITableViewCell {    
      let topic = categories[indexPath.section].topics[indexPath.row]
      let cell = tableView.dequeueReusableCellWithIdentifier("topicCell",forIndexPath: indexPath)
      cell.textLabel?.text = topic
  
      return cell
  }    
  </code></pre>
  
  <p>I also have categories defined at the top of TopicsTableViewController as well so I could get the correct row count based on the topics count... </p>
  
  <pre><code>var categories = Category.getCategories() 
  </code></pre>
  
  <p>I think I'm missing something in my didSelectRowAtIndexPath or in my prepareForSegue.  I think the fact that my topics are an array that is returned within an array of Category from the getCategories() function is screwing me up somehow. </p>
  
  <p><strong>Note:</strong> 
  My segue between the CategoryTableViewController and the TopicsTableViewController was created on the storyboard by ctrl + dragging from the cell in CategoryTableViewController to the TopicsTableViewController.  </p>
  
  <p>Any help is greatly appreciate!  </p>
  
  <p>Thanks :) </p>