I'm trying to delete a tableView Cell with the NSFetchedResultsControllerDelegate. I'm using this if statement in the TabbleView commit function.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
if let person = fetchedResultsController.object(at: indexPath){
fetchedResultsController.managedObjectContext.delete(person)
}
}
}
This is the error I get: Initializer for conditional binding must have Optional type, not 'Person'
If I cast the person as an optinoal Person
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
if let person = fetchedResultsController.object(at: indexPath) as? Person{
fetchedResultsController.managedObjectContext.delete(person)
}
}
}
I get this warning: Non-optional expression of type 'Person' used in a check for optionals
It seems to be working with the warning, but I would like to clear this up so that I better understand what is going on.