Skip to content

Instantly share code, notes, and snippets.

View ctrevarthen's full-sized avatar

Chris Trevarthen ctrevarthen

View GitHub Profile
@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 / 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 / appdelegate.swift
Created November 24, 2015 16:08
ShopQuick - App Delegate
func applicationWillEnterForeground(application: UIApplication) {
PrioritiesManager.sharedInstance.checkForResetTrigger()
}
@ctrevarthen
ctrevarthen / appdelegate.swift
Last active November 24, 2015 15:55
ShopQuick - PrioritiesManager
func applicationWillEnterForeground(application: UIApplication) {
PrioritiesManager.sharedInstance.checkForResetTrigger()
}
@ctrevarthen
ctrevarthen / gist:f161b391eae8c5420c63
Last active November 19, 2015 03:38
ShopQuick - Shopping List Manager - DRY
class ShoppingListManager : ProductManager {
static let sharedInstance = ShoppingListManager()
override init() {
super.init()
self.productsKey = "com.detroitlabs.shopfast.products"
self.loadProductsFromDefaults()
}
@ctrevarthen
ctrevarthen / gist:27f926974beead37635b
Last active November 19, 2015 03:38
ShopQuick - Favorites Manager DRY
class FavoritesManager : ProductManager {
static let sharedInstance = FavoritesManager()
override init() {
super.init()
self.productsKey = "com.detroitlabs.shopfast.favorites"
self.loadProductsFromDefaults()
}
@ctrevarthen
ctrevarthen / gist:494b0b003fc13ab92022
Last active November 19, 2015 03:37
ShopQuick - Shopping List VC - Strikethru
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
}
@ctrevarthen
ctrevarthen / gist:ece20a5816ff240d31a0
Last active November 19, 2015 03:37
ShopQuick - Shopping List Manager - Is Favorited?
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())
}
@ctrevarthen
ctrevarthen / gist:394b1f44cb7eb26f575c
Last active November 19, 2015 03:37
ShopQuick - Favorites Manager - Is Favorited?
func isProductFavorited(product: Product) -> Bool {
if let _ = self.findProductByName(product.name) {
return true
}
else {
return false
}
}
func findProductByName(name: String) -> Product? {
@ctrevarthen
ctrevarthen / gist:ce8eb0698eaba854f188
Last active November 19, 2015 03:37
ShopQuick - Favorites VC Left Buttons
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
}