Last active
November 19, 2015 03:35
-
-
Save ctrevarthen/c53d2a664c88cc375be9 to your computer and use it in GitHub Desktop.
ShopQuick - Purchased Product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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