title: delete section at indexPath swift
body: <p>I have an array which populates a table view - myPosts.</p>
  
  <p>The first row of the table view is not part of the array.</p>
  
  <p>Each row is its own section (with its own custom footer)</p>
  
  <p>I am trying to perform a delete with the following code:</p>
  
  <pre><code>func tableView(profileTableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
              if (editingStyle == UITableViewCellEditingStyle.Delete) {
                  myPosts?.removeAtIndex(indexPath.section - 1)
                  profileTableView.beginUpdates()
                  let indexSet = NSMutableIndexSet()
                  indexSet.addIndex(indexPath.section - 1)
                  profileTableView.deleteSections(indexSet, withRowAnimation: UITableViewRowAnimation.Automatic)
                  profileTableView.deleteRowsAtIndexPaths([indexPath],  withRowAnimation: UITableViewRowAnimation.Automatic)
                  profileTableView.endUpdates()
                  ...
                  WS Call 
                  ...
              }
  }
  </code></pre>
  
  <p>And the log is reporting the following:</p>
  
  <blockquote>
    <p>Invalid update: invalid number of rows in section 0.  The number of
    rows contained in an 
            existing section after the update (1) must be equal to the number of rows contained in that 
        section before the update (1), plus or minus the number of rows inserted or deleted from 
        that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out 
        of that section (0 moved in, 0 moved out).'</p>
  </blockquote>
  
  <p>Obviously the issue is related to 0 moved in, 0 moved out but I don't understand why that is? or what the solution would be?</p>
  
  <p>Number of sections in tableView is as follows:</p>
  
  <pre><code>func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          if self.myPosts == nil
          {
  
              return 1
          }
          return self.myPosts!.count + 1
      }
  </code></pre>