Skip to content

Instantly share code, notes, and snippets.

@ctrevarthen
Last active November 19, 2015 03:35
Show Gist options
  • Save ctrevarthen/c53d2a664c88cc375be9 to your computer and use it in GitHub Desktop.
Save ctrevarthen/c53d2a664c88cc375be9 to your computer and use it in GitHub Desktop.
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
init(name: String, qty: Int) {
self.name = name
self.qty = qty
}
required init(coder aDecoder: NSCoder) {
if let name = aDecoder.decodeObjectForKey(nameKey) as? String {
self.name = name
}
if let qty = aDecoder.decodeObjectForKey(qtyKey) as? Int {
self.qty = qty
}
if let purchased = aDecoder.decodeObjectForKey(purchasedKey) as? Bool {
self.purchased = purchased
}
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(self.name, forKey: nameKey)
aCoder.encodeObject(self.qty, forKey: qtyKey)
aCoder.encodeObject(self.purchased, forKey: purchasedKey)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment