Swift 2.0转换问题NSFetchedResultsController didChangeObject

时间:2015-09-23 10:30:42

标签: swift core-data nsfetchedresultscontroller

在Swift 2.0中转换后我无法解决问题:

  

“Objective-C方法   '控制器:didChangeObject:atIndexPath:forChangeType:newIndexPath:'   方法提供   '控制器(:didChangeObject:atIndexPath:forChangeType:newIndexPath :)'   与可选的需求方法冲突   '控制器(:didChangeObject:atIndexPath:forChangeType:newIndexPath :)'   在协议'NSFetchedResultsControllerDelegate'“

请帮帮我。 并感谢提前

func controllerWillChangeContent(controller: NSFetchedResultsController) {
    tableView.beginUpdates()
}

func controller(controller: NSFetchedResultsController, didChangeObject anObject: NSManagedObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {

    // the issue is here

    switch type {

    case NSFetchedResultsChangeType.Insert:
        if let newIndex = newIndexPath {
            tableView.insertRowsAtIndexPaths([newIndex], withRowAnimation: UITableViewRowAnimation.Automatic)
        }

    case NSFetchedResultsChangeType.Delete:
        if let index = indexPath {
            tableView.deleteRowsAtIndexPaths([index], withRowAnimation: UITableViewRowAnimation.Automatic)
        }
    }
}

func controllerDidChangeContent(controller: NSFetchedResultsController) {
    tableView.endUpdates()
}

1 个答案:

答案 0 :(得分:5)

更改 public bool Delete<E>(E entity) where E : class { DataContext.Entry(entity).State = System.Data.EntityState.Deleted; DataContext.SaveChanges() } 的来电didChangeObject anObject: NSManagedObject。新方法如下所示:

didChangeObject anObject: AnyObject

NSFetchedResultsController delegate methods