Created
November 24, 2015 16:17
-
-
Save ctrevarthen/7535460a100788c03262 to your computer and use it in GitHub Desktop.
ShopQuick - End shopping trip
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() | |
let prioritiesManager = PrioritiesManager.sharedInstance | |
func markPurchasedAtIndex(index: Int) { | |
let product = self.products[index] | |
product.purchased = true | |
self.prioritiesManager.addProduct(product) | |
if !self.hasUnpurchasedItems() { | |
self.prioritiesManager.lastProductPurchased = nil | |
} | |
self.saveProductsToDefaults() | |
} | |
func hasUnpurchasedItems() -> Bool { | |
let unpurchased = self.products.filter { (p : Product) -> Bool in | |
return !p.purchased | |
} | |
return unpurchased.count > 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment