[indexPath!] 和 [newIndexPath!] 上的错误 - 消息"无法将类型'NSIndexPath?' 的值转换为预期的元素类型'IndexPath'


// Errors on [indexPath!] and [newIndexPath!] ---- the message "Cannot convert value of type 'NSIndexPath?' to expected element type 'Array<IndexPath>.ArrayLiteralElement' (aka 'IndexPath')" 
func controller(controller:   
NSFetchedResultsController<NSFetchRequestResult>, didChangeObject
anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, 
forChangeType type: NSFetchedResultsChangeType, newIndexPath: 
NSIndexPath?) {
switch(type) {
case .insert:
self.heroTableView.insertRowsAtIndexPaths([newIndexPath!],  
withRowAnimation: .fade)
case .delete:
self.heroTableView.deleteRowsAtIndexPaths([indexPath!],     
withRowAnimation: .fade) 
default:
()
}
}

//谢谢你,Willeke。//我发布这篇文章是为了那些会遇到同样错误的人。

func controller(controller:   
NSFetchedResultsController<NSFetchRequestResult>, didChangeObject
anObject: AnyObject, atIndexPath indexPath: IndexPath?, 
forChangeType type: NSFetchedResultsChangeType, newIndexPath: 
IndexPath?) {
switch(type) {
case .insert:
self.heroTableView.insertRows(at: [newIndexPath!], with: .fade)

case .delete:
self.heroTableView.deleteRows(at: [indexPath!], with: .fade)    

default:
()
}
}

相关内容

最新更新