Swift 2.0 转换问题 NSFetchedResultsController didChangeObject

Posted

技术标签:

【中文标题】Swift 2.0 转换问题 NSFetchedResultsController didChangeObject【英文标题】:Swift 2.0 convert issue NSFetchedResultsController didChangeObject 【发布时间】:2015-09-23 10:30:41 【问题描述】:

在 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()

【问题讨论】:

签名现在是didChangeObject anObject: AnyObject? 迈克·波拉德 - 谢谢!!! 【参考方案1】:

将呼叫 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的主要内容,如果未能解决你的问题,请参考以下文章