Skip to content

Instantly share code, notes, and snippets.

View ctrevarthen's full-sized avatar

Chris Trevarthen ctrevarthen

View GitHub Profile
@ctrevarthen
ctrevarthen / gist:875e723f58ee8d5bc180
Last active November 19, 2015 03:37
ShopQuick: Mark as Purchased - VC
func swipeableTableViewCell(cell: SWTableViewCell!, didTriggerLeftUtilityButtonWithIndex index: Int) {
switch index {
case LeftUtilityButtons.Favorite.rawValue:
if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! {
// TODO: Add Favorites functionality here
}
case LeftUtilityButtons.Purchase.rawValue:
if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! {
self.shoppingListManager.markPurchasedAtIndex(indexPath.row)
}
@ctrevarthen
ctrevarthen / gist:c53d2a664c88cc375be9
Last active November 19, 2015 03:35
ShopQuick - Purchased Product
class Product : NSObject, NSCoding {
let nameKey = "name"
let qtyKey = "qty"
let purchasedKey = "purchased"
var name : String = ""
var qty : Int = 0
var purchased : Bool = false
@ctrevarthen
ctrevarthen / gist:b05c6813c83e217ecf83
Last active November 19, 2015 03:36
ShopQuick - ShoppingListManager mark as purchased
func markPurchasedAtIndex(index: Int) {
self.products[index].purchased = true
self.saveProductsToDefaults()
}
@ctrevarthen
ctrevarthen / gist:57fb040cdc1aadf5fe2b
Last active November 19, 2015 03:37
ShopQuick - Favorites Manager Basic
class FavoritesManager {
static let sharedInstance = FavoritesManager()
let userDefaults = NSUserDefaults.standardUserDefaults()
let productsKey = "com.detroitlabs.shopfast.favorites"
private var products : [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
}
@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: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: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: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: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()
}