Skip to content

Instantly share code, notes, and snippets.

View ctrevarthen's full-sized avatar

Chris Trevarthen ctrevarthen

View GitHub Profile
@ctrevarthen
ctrevarthen / appdelegate.swift
Last active November 24, 2015 15:55
ShopQuick - PrioritiesManager
func applicationWillEnterForeground(application: UIApplication) {
PrioritiesManager.sharedInstance.checkForResetTrigger()
}
@ctrevarthen
ctrevarthen / appdelegate.swift
Created November 24, 2015 16:08
ShopQuick - App Delegate
func applicationWillEnterForeground(application: UIApplication) {
PrioritiesManager.sharedInstance.checkForResetTrigger()
}
@ctrevarthen
ctrevarthen / manager_reset.swift
Created November 24, 2015 16:09
ShopQuick - Priorities Manager Reset
let resetKey = "com.detroitlabs.shopfast.ResetPriorities"
func checkForResetTrigger() {
let userDefaults = NSUserDefaults.standardUserDefaults()
let shouldReset = userDefaults.boolForKey(resetKey)
if shouldReset {
self.products = []
userDefaults.removeObjectForKey(self.productsKey)
userDefaults.setBool(false, forKey: resetKey)
}
@ctrevarthen
ctrevarthen / root.plist
Created November 24, 2015 16:10
ShopQuick - Root.plist
<dict>
<key>Title</key>
<string>ClearDataGroup</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<false/>
<key>Key</key>
@ctrevarthen
ctrevarthen / rule_final.swift
Created November 24, 2015 16:12
ShopQuick - Priorities Rule 3 Final
class PrioritiesManager : ProductManager {
static let sharedInstance = PrioritiesManager()
var productsInThisTrip : [Product]?
func addProduct(product: Product) {
let newProduct = Product(name: product.name, qty: 0)
@ctrevarthen
ctrevarthen / rule3_revised.swift
Created November 24, 2015 16:13
ShopQuick - Priorities Rule 3 Revised
func addProduct(product: Product) {
let newProduct = Product(name: product.name, qty: 0)
// if the product exists
if self.doesProductExist(newProduct.name) {
// if there is a last item purchased
if let lastProduct = self.lastProductPurchased {
@ctrevarthen
ctrevarthen / rule3.swift
Last active November 24, 2015 17:16
ShopQuick - Priorities Rule 3
func addProduct(product: Product) {
let newProduct = Product(name: product.name, qty: 0)
// if the product exists
if self.doesProductExist(newProduct.name) {
// if there is a last item purchased
if let lastProduct = self.lastProductPurchased {
@ctrevarthen
ctrevarthen / shoppinglist.swift
Created November 24, 2015 16:17
ShopQuick - End shopping trip
class ShoppingListManager : ProductManager {
static let sharedInstance = ShoppingListManager()
let prioritiesManager = PrioritiesManager.sharedInstance
func markPurchasedAtIndex(index: Int) {
let product = self.products[index]
@ctrevarthen
ctrevarthen / rule4.swift
Last active November 24, 2015 17:17
ShopQuick - Rule 4
func addProduct(product: Product) {
let newProduct = Product(name: product.name, qty: 0)
// if the product exists
if self.doesProductExist(newProduct.name) {
// if there is a last item purchased
if let lastProduct = self.lastProductPurchased {
@ctrevarthen
ctrevarthen / rule2.swift
Created November 24, 2015 16:18
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