Please note, this blog entry is from a previous course. You might want to check out the current one.
Make the “most recent searches” table be editable (i.e. let the user swipe left to delete the ones they don’t like).
We need a new method for our model/data source to be able to delete an entry from the user defaults:
func removeAtIndex(index: Int) { var currentSearches = values currentSearches.removeAtIndex(index) values = currentSearches }
… and use it before removing the line from the table:
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if editingStyle == .Delete { RecentSearches().removeAtIndex(indexPath.row) tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) } }
The complete code for extra task #5 is available on GitHub.