title: didSelectRowAtIndexPath and a practical way to convert Objective-C to Swift?
body: <p>I am trying to convert this to swift but I am blocked. How can I achieve this now and in the future?</p>
  
  <pre><code>    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  
      if (self.tableView(tableView, canCollapseSection:indexPath.section)) {
  
  
  
              // only first row toggles exapand/collapse
              (tableView, deselectRowAtIndexPath:indexPath, animated:true);
  
              var section: NSInteger = indexPath.section;
              var currentlyExpanded: Bool = expandedSections.containsIndex(section);
              var rows: NSInteger;
  
              var tmpArray: NSMutableArray;
  
              if currentlyExpanded
              {
                  rows = (self.tableView(tableView, numberOfRowsInSection:section))
                  expandedSections.removeIndex(section)
              }
              else
              {
                  expandedSections.addIndex(section)
                  rows = (self.tableView(tableView, numberOfRowsInSection:section))
              }
  
              for var i = 1; i &lt; rows; ++i
              {
                  var tmpIndexPath: NSIndexPath = (indexPathForRow:i, inSection:section);
                  tmpArray.addObject(tmpIndexPath);
              }
  
              var cell: UITableViewCell = (self.tableView, cellForRowAtIndexPath:indexPath);
  
              if currentlyExpanded
              {
                  (tableView, deleteRowsAtIndexPaths:tmpArray, withRowAnimation:UITableViewRowAnimationFade);
  
              }
              else
              {
                  (tableView, insertRowsAtIndexPaths:tmpArray, withRowAnimation:UITableViewRowAnimationFade);
              }
          }
  
  
  
  }
  </code></pre>
  
  <p>I can't find the right code for the for flow, where "var tmpIndexPath: NSIndexPath is equal to (indexPathForRow:i, inSection:section);" and the part with the row animations seems to have no answer to me.
  Thanks in advance!</p>
  
  <p>EDIT: This is the Objective-C code that I am trying to convert.</p>
  
  <pre><code>    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath (NSIndexPath *)indexPath {
       if ([self tableView:tableView canCollapseSection:indexPath.section])
      {
       if (!indexPath.row)
       {
          // only first row toggles exapand/collapse
          [tableView deselectRowAtIndexPath:indexPath animated:YES];
  
          NSInteger section = indexPath.section;
          BOOL currentlyExpanded = [expandedSections containsIndex:section];
          NSInteger rows;
  
          NSMutableArray *tmpArray = [NSMutableArray array];
  
          if (currentlyExpanded)
          {
              rows = [self tableView:tableView numberOfRowsInSection:section];
              [expandedSections removeIndex:section];
          }
          else
          {
              [expandedSections addIndex:section];
              rows = [self tableView:tableView numberOfRowsInSection:section];
          }
  
          for (int i=1; i&lt;rows; i++)
          {
              NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
                                                             inSection:section];
              [tmpArray addObject:tmpIndexPath];
          }
  
          UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  
          if (currentlyExpanded)
          {
              [tableView deleteRowsAtIndexPaths:tmpArray
                               withRowAnimation:UITableViewRowAnimationFade];
  
              cell.accessoryType = UITableViewCellAccessoryNone;
          }
          else
          {
              [tableView insertRowsAtIndexPaths:tmpArray
                               withRowAnimation:UITableViewRowAnimationFade];
  
              cell.accessoryType = UITableViewCellAccessoryNone;
          }
      }
  }
  </code></pre>