Aconselho que você passe a usar NSFetchedResultController. Isso é perfeito para lidar com edição de linhas + coredata em uma TableView.
Vou descrever um passo a passo básico do que você deve fazer pra conseguir começar a usar NSFetchedResultController:
- Faça sua classe herdar de NSFetchedResultsControllerDelegate;
Depois cria uma variável da seguinte forma:
lazy var fetchedResultsController: NSFetchedResultsController = {
let fetchRequest = NSFetchRequest(entityName: "NomeDaSuaEntidade")
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "atributoParaOrdenar", ascending: true)]
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.sharedContext, sectionNameKeyPath: nil, cacheName: nil)
return fetchedResultsController
}()
Na viewDidLoad adicione o seguinte trecho de código:
...
do {
try fetchedResultsController.performFetch()
} catch {}
fetchedResultsController.delegate = self
...
Pra preencher a tabela no método cellForRowAtIndePath recupere os objetos da seguinte forma:
...
let objeto = fetchedResultsController.objectAtIndexPath(indexPath) as! NomeDoSeuObjeto
...
No método numberOfRowsInSection recupere o número de itens da seguinte forma:
...
let sectionInfo = self.fetchedResultsController.sections![section]
return sectionInfo.numberOfObjects
...
Agora o grande charme do NSFetchedResultController que faz valer tanto a pena usar esse delegate o método que cuida das inserções, remoções, atualizações e movimentações de linhas da tabela:
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
switch type {
case .Insert:
self.tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade)
case .Delete:
self.tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
case .Update:
let cell = tableView.cellForRowAtIndexPath(indexPath!) as! ArtistCell
let artist = controller.objectAtIndexPath(indexPath!) as! NomeDoSeuObjeto
//preenche celula com dados do objeto
case .Move:
self.tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
self.tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade)
}
}
Pra finalizar adicione os seguintes métodos pra que tudo funcione perfeitamente:
func controllerWillChangeContent(controller: NSFetchedResultsController) {
self.tableView.beginUpdates()
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
self.tableView.endUpdates()
}
Seguindo os passos acima você vai conseguir fazer a remoção de uma célula funcionar além de poder aproveitar de outros benefícios que esse delegate tem a oferecer.
Vou te passar também o link de um tutorial muito bom mostrando como se faz para poder complementar o que falei acima: http://code.tutsplus.com/tutorials/core-data-and-swift-nsfetchedresultscontroller--cms-25072 (Sei que o tutorial está em Inglês, mas não achei nenhum bom em português)