当我将Xcode更新为6.3和Swift 1.2时,这导致下面的函数产生这个不祥的警告:
'controller(_:didChangeObject:atIndexPath:forChangeType:newIndexPath :)'的参数具有与协议'NSFetchedResultsControllerDelegate'预期不同的选项
这是函数头:
func controller(控制器:NSFetchedResultsController, didChangeObject anObject:AnyObject,atIndexPath indexPath: NSIndexPath!,forChangeType类型:NSFetchedResultsChangeType, newIndexPath:NSIndexPath!){
当我遵循Xcode建议的时候,取而代之的是!使用?,Xcode编译器拒绝使用索引路径的行,所以我打开这些值,让我这样:
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
switch type
{
case .Insert:
if let newPath = newIndexPath
{
tableView.insertRowsAtIndexPaths([newPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
case .Delete:
if let path = indexPath
{
tableView.deleteRowsAtIndexPaths([path], withRowAnimation: UITableViewRowAnimation.Automatic)
}
default:
break
}
}
现在,使用此方法插入和删除行时出现运行时错误。没有错误信息或洞察正在发生的事情。这是解决警告信息的正确方法吗?