Skip to content

Instantly share code, notes, and snippets.

View ctrevarthen's full-sized avatar

Chris Trevarthen ctrevarthen

View GitHub Profile
@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: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: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: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:1a999d68c8f2de64fa43
Last active November 19, 2015 03:40
ShopQuick: Delete with utility
func swipeableTableViewCell(cell: SWTableViewCell!, didTriggerRightUtilityButtonWithIndex index: Int) {
switch index {
case RightUtilityButtons.Delete.rawValue:
if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! {
self.shoppingListTableView.beginUpdates()
self.shoppingListTableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Bottom)
self.shoppingListManager.removeProductAtIndex(indexPath.row)
self.shoppingListTableView.endUpdates()
}
default:
@ctrevarthen
ctrevarthen / gist:58fb6528572e2eebd7af
Last active November 19, 2015 03:39
BVReorderTableView Delegate Methods
// MARK: ReorderTableView Delegate Methods
func saveObjectAndInsertBlankRowAtIndexPath(indexPath: NSIndexPath!) -> AnyObject! {
let p = self.shoppingListManager.productAtIndex(indexPath.row)
self.shoppingListManager.replaceProductAtIndex(indexPath.row, withProduct: Product(name: "", qty: 0))
return p
}
func moveRowAtIndexPath(fromIndexPath: NSIndexPath!, toIndexPath: NSIndexPath!) {
let p = self.shoppingListManager.productAtIndex(fromIndexPath.row)
@ctrevarthen
ctrevarthen / gist:4f3e15c0635847e3e158
Last active November 19, 2015 03:40
ShopQuick - ShoppingListVC with SWTableViewCell Delegate methods - actions
enum LeftUtilityButtons: Int {
case Purchase
case Favorite
}
enum RightUtilityButtons: Int {
case Delete
}
// MARK: SWTableViewCell Delegate Methods
@ctrevarthen
ctrevarthen / gist:2f42f86d155da02f1157
Last active November 19, 2015 03:39
ShopQuick: SWTableViewCell buttons
// MARK: TableViewDataSource Delegate Methods
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("Product Cell") as? ProductCell {
cell.productNameLabel.text = self.shoppingListManager.productAtIndex(indexPath.row).name
// Set up SWTableViewCell utility buttons
cell.delegate = self
cell.leftUtilityButtons = self.leftButtons()
@ctrevarthen
ctrevarthen / gist:c82937dd90ec7a9cef11
Last active November 19, 2015 03:39
ShopQuick - ShoppingListVC with SWTableViewCell Delegate methods - swipe control
// Allow just one cell's utility button to be open at once
func swipeableTableViewCellShouldHideUtilityButtonsOnSwipe(cell: SWTableViewCell!) -> Bool {
return true
}
// Determines which swipe directions are allowed per cell
func swipeableTableViewCell(cell: SWTableViewCell!, canSwipeToState state: SWCellState) -> Bool {
switch state {
case SWCellState.CellStateLeft:
@ctrevarthen
ctrevarthen / gist:27f780533be13826e7ee
Last active November 19, 2015 03:39
ShopQuick - ProductCell with SWTableViewCell
import UIKit
import SWTableViewCell
class ProductCell : SWTableViewCell {
@IBOutlet weak var productNameLabel: UILabel!
}