Please look at the following code:
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler: {
(action : UITableViewRowAction, indexPath : NSIndexPath) -> Void in
if let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext{
let restaurantToDelete = self.fetchResultController.objectAtIndexPath(indexPath) as! Restaurant
managedObjectContext.deleteObject(restaurantToDelete)
// Saving managedObjectContext instance, and catch errors if it fails
do {
try managedObjectContext.save()
} catch let error as NSError {
print("Error: \(error.localizedDescription)")
}
}
})
return deleteAction
}
the error message from Xcode is : Invalid conversion from throwing function of type '(UITableViewRowAction, NSIndexPath) throws -> Void' to non-throwing function type '(UITableViewRowAction, NSIndexPath) -> Void'
I know the problem is managedObjectContext.save() will throw errors and this is not allowed in the completion handler. I found some blog articles where they modified the closure parameters in order to make the error handling in a closure workable. While here the definition of the function is given by apple, so how can i fix this issue? Thanks a lot! :D