Database Reference
In-Depth Information
println ( "Could not save: \(error) " )
}
//5
tableView. deleteRowsAtIndexPaths ([indexPath],
withRowAnimation: UITableViewRowAnimation . Automatic )
}
}
This table view data source method is called when you tap the red Delete button.
Let's go step by step through the code:
1. First, you get a reference to the walk you want to delete.
2. Removing a Core Data object from an ordered to-many relationship is as
complicated as adding one. First, you create a mutable copy of the NSOrderedSet ,
remove the walk in that copy, then set an immutable copy of the new set back on
the currently selected dog. Whew!
3. You've removed the walk from the dog's list of walks, but the walk itself is still
hanging around. Remove the walk from Core Data by calling
NSManagedObjectContext 's deleteObject method.
4. No changes are final until you save your managed object context, not even
deletions!
5. Finally, you animate the table view to tell the user about the deletion.
Build and run the app one more time. You should have several walks from previous
runs. Pick any and swipe to the left:
Tap on the Delete button to remove the walk. Verify that the walk is actually gone
by terminating the app and re-launching from scratch.
The walk you just removed is gone for good. Core Data giveth and Core Data
taketh away.
Search WWH ::




Custom Search