Created
November 24, 2015 16:18
-
-
Save ctrevarthen/3d231cabf6771f2de223 to your computer and use it in GitHub Desktop.
ShopQuick - Rule 2
This file contains 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 addProduct(product: Product) { | |
let newProduct = Product(name: product.name, qty: 0) | |
if let _ = lastProductPurchased, | |
let index : Int = self.findIndexForProductName(lastProductPurchased!.name) { | |
// if the new product already exists | |
if let _ = self.findProductByName(newProduct.name) { | |
// do nothing -- Rule #2 | |
} | |
else { | |
self.insertProduct(newProduct, atIndex: index + 1) | |
} | |
} | |
lastProductPurchased = product | |
self.saveProductsToDefaults() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment