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
| 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 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 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 swipeableTableViewCell(cell: SWTableViewCell!, didTriggerLeftUtilityButtonWithIndex index: Int) { | |
| switch index { | |
| case LeftUtilityButtons.AddToList.rawValue: | |
| if let indexPath = self.favoritesTableView.indexPathForCell(cell) as NSIndexPath! { | |
| let fav = self.favoritesManager.productAtIndex(indexPath.row) | |
| self.shoppingListManager.addProduct(fav) | |
| } | |
| default: | |
| break | |
| } |
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 isProductFavorited(product: Product) -> Bool { | |
| if let _ = self.findProductByName(product.name) { | |
| return true | |
| } | |
| else { | |
| return false | |
| } | |
| } | |
| func findProductByName(name: String) -> 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 leftButtonsForProduct(product: Product) -> [UIButton] { | |
| let buttons : NSMutableArray = NSMutableArray() | |
| if self.favoritesManager.isProductFavorited(product) { | |
| buttons.sw_addUtilityButtonWithColor(UIColor(red: 224/255, green: 224/255, blue: 103/255, alpha: 1), title: "Faved") | |
| } | |
| else { | |
| buttons.sw_addUtilityButtonWithBackgroundColor(UIColor.whiteColor(), title: "Fav", titleColor: UIColor.blackColor()) | |
| } | |
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 tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
| if let cell = tableView.dequeueReusableCellWithIdentifier("Product Cell") as? ProductCell { | |
| let product = self.shoppingListManager.productAtIndex(indexPath.row) | |
| if product.purchased { | |
| let attr = [NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue] | |
| let attrString = NSAttributedString(string: product.name, attributes: attr) | |
| cell.productNameLabel.attributedText = attrString | |
| } |
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 : ProductManager { | |
| static let sharedInstance = FavoritesManager() | |
| override init() { | |
| super.init() | |
| self.productsKey = "com.detroitlabs.shopfast.favorites" | |
| self.loadProductsFromDefaults() | |
| } |
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 ShoppingListManager : ProductManager { | |
| static let sharedInstance = ShoppingListManager() | |
| override init() { | |
| super.init() | |
| self.productsKey = "com.detroitlabs.shopfast.products" | |
| self.loadProductsFromDefaults() | |
| } | |