gpt4 book ai didi

Swift 2.0 转换问题 NSFetchedResultsController didChangeObject

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:51 24 4
gpt4 key购买 nike

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

"Objective-C method 'controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:' provided by method 'controller(:didChangeObject:atIndexPath:forChangeType:newIndexPath:)' conflicts with optional requirement method 'controller(:didChangeObject:atIndexPath:forChangeType:newIndexPath:)' in protocol '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()
}

最佳答案

didChangeObject anObject: NSManagedObject 的调用更改为 didChangeObject anObject: AnyObject。新方法如下所示:

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

}

NSFetchedResultsController delegate methods

关于Swift 2.0 转换问题 NSFetchedResultsController didChangeObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32737201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com