title: UITableView Deleting Row. Swift 2
body: <p>I have a table view which is been created programatically based on an array. I have enabled the editing button on the button item and I want to be able to delete the value on the row from the array which, as a result is removed from the table view. </p>
  
  <p>I have the following code:</p>
  
  <pre><code>class TableViewController: UITableViewController {
  
  
  var data = ["Apple", "Apricot", "Banana", "Blueberry", "Cantaloupe", "Cherry",
      "Clementine", "Coconut", "Cranberry", "Fig", "Grape", "Grapefruit",
      "Kiwi fruit", "Lemon", "Lime", "Lychee", "Mandarine", "Mango",
      "Melon", "Nectarine", "Olive", "Orange", "Papaya", "Peach",
      "Pear", "Pineapple", "Raspberry", "Strawberry"]
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.navigationItem.rightBarButtonItem = self.editButtonItem()
  }
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      // #warning Incomplete implementation, return the number of sections
      return 3
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      // #warning Incomplete implementation, return the number of rows
      return data.count
  }
  
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier("test", forIndexPath: indexPath)
  
      cell.textLabel?.text = data[indexPath.row]
      return cell
  }
  
  
  
  // Override to support conditional editing of the table view.
  override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -&gt; Bool {
      // Return false if you do not want the specified item to be editable.
      return true
  }
  
  
  
  // Override to support editing the table view.
  override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
      if editingStyle == .Delete {
  
  
          data.removeAtIndex(indexPath.row)
  
          tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
      } else if editingStyle == .Insert {
          // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
      }    
  }
  }
  </code></pre>
  
  <p>when I run this, and click the delete button on a row I get the following error:</p>
  
  <blockquote>
    <p>malloc: error for object 0x7ffc69f4d580: incorrect checksum for freed
    object - object was probably modified after being freed. set a
    breakpoint in malloc_error_break to debug</p>
  </blockquote>
  
  <p>Any help would be greatly appreciated :)</p>