cs193p – Project #4 Assignment #4 Extra Task #5

By File:We_Can_Do_It!.jpg: J. Howard Miller, artist employed by Westinghouse, poster used by the War Production Co-ordinating Committee derivative work: Tom Morris (This file was derived from: We Can Do It!.jpg:) [Public domain], via Wikimedia Commons

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
        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 {
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

The complete code for extra task #5 is available on GitHub.


Leave a Reply

Your email address will not be published.