Skip to content

Instantly share code, notes, and snippets.

@ctrevarthen
Created November 24, 2015 16:18
Show Gist options
  • Save ctrevarthen/3d231cabf6771f2de223 to your computer and use it in GitHub Desktop.
Save ctrevarthen/3d231cabf6771f2de223 to your computer and use it in GitHub Desktop.
ShopQuick - Rule 2
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