This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FavoritesManager { | |
| static let sharedInstance = FavoritesManager() | |
| let userDefaults = NSUserDefaults.standardUserDefaults() | |
| let productsKey = "com.detroitlabs.shopfast.favorites" | |
| private var products : [Product] = [] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func markPurchasedAtIndex(index: Int) { | |
| self.products[index].purchased = true | |
| self.saveProductsToDefaults() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Product : NSObject, NSCoding { | |
| let nameKey = "name" | |
| let qtyKey = "qty" | |
| let purchasedKey = "purchased" | |
| var name : String = "" | |
| var qty : Int = 0 | |
| var purchased : Bool = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func swipeableTableViewCell(cell: SWTableViewCell!, didTriggerLeftUtilityButtonWithIndex index: Int) { | |
| switch index { | |
| case LeftUtilityButtons.Favorite.rawValue: | |
| if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! { | |
| // TODO: Add Favorites functionality here | |
| } | |
| case LeftUtilityButtons.Purchase.rawValue: | |
| if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! { | |
| self.shoppingListManager.markPurchasedAtIndex(indexPath.row) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func swipeableTableViewCell(cell: SWTableViewCell!, didTriggerRightUtilityButtonWithIndex index: Int) { | |
| switch index { | |
| case RightUtilityButtons.Delete.rawValue: | |
| if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! { | |
| self.shoppingListTableView.beginUpdates() | |
| self.shoppingListTableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Bottom) | |
| self.shoppingListManager.removeProductAtIndex(indexPath.row) | |
| self.shoppingListTableView.endUpdates() | |
| } | |
| default: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: ReorderTableView Delegate Methods | |
| func saveObjectAndInsertBlankRowAtIndexPath(indexPath: NSIndexPath!) -> AnyObject! { | |
| let p = self.shoppingListManager.productAtIndex(indexPath.row) | |
| self.shoppingListManager.replaceProductAtIndex(indexPath.row, withProduct: Product(name: "", qty: 0)) | |
| return p | |
| } | |
| func moveRowAtIndexPath(fromIndexPath: NSIndexPath!, toIndexPath: NSIndexPath!) { | |
| let p = self.shoppingListManager.productAtIndex(fromIndexPath.row) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum LeftUtilityButtons: Int { | |
| case Purchase | |
| case Favorite | |
| } | |
| enum RightUtilityButtons: Int { | |
| case Delete | |
| } | |
| // MARK: SWTableViewCell Delegate Methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: TableViewDataSource Delegate Methods | |
| func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
| if let cell = tableView.dequeueReusableCellWithIdentifier("Product Cell") as? ProductCell { | |
| cell.productNameLabel.text = self.shoppingListManager.productAtIndex(indexPath.row).name | |
| // Set up SWTableViewCell utility buttons | |
| cell.delegate = self | |
| cell.leftUtilityButtons = self.leftButtons() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Allow just one cell's utility button to be open at once | |
| func swipeableTableViewCellShouldHideUtilityButtonsOnSwipe(cell: SWTableViewCell!) -> Bool { | |
| return true | |
| } | |
| // Determines which swipe directions are allowed per cell | |
| func swipeableTableViewCell(cell: SWTableViewCell!, canSwipeToState state: SWCellState) -> Bool { | |
| switch state { | |
| case SWCellState.CellStateLeft: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import SWTableViewCell | |
| class ProductCell : SWTableViewCell { | |
| @IBOutlet weak var productNameLabel: UILabel! | |
| } |