Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct GroceryList {
- let ref: DatabaseReference?
- let key: String
- let groceryListName: String
- init(groceryListName: String, key: String = "") {
- self.ref = nil
- self.key = key
- self.groceryListName = groceryListName
- }
- init?(snapshot: DataSnapshot) {
- guard
- let value = snapshot.value as? [String: AnyObject],
- let groceryListName = value["groceryListName"] as? String else { return nil }
- self.ref = snapshot.ref
- self.key = snapshot.key
- self.groceryListName = groceryListName
- }
- func toAnyObject() -> Any {
- return ["groceyListName": [Items.toAnyObject]]
- }
- struct Items {
- let ref: DatabaseReference?
- let key: String
- let product: String
- let price: String
- var completed: Bool
- init(product: String, price: String, completed: Bool, key: String = "") {
- self.ref = nil
- self.key = key
- self.product = product
- self.price = price
- self.completed = completed
- }
- init?(snapshot: DataSnapshot) {
- guard
- let value = snapshot.value as? [String: AnyObject],
- let product = value["product"] as? String,
- let price = value["price"] as? String,
- let completed = value["completed"] as? Bool else { return nil }
- self.ref = snapshot.ref
- self.key = snapshot.key
- self.product = product
- self.price = price
- self.completed = completed
- }
- func toAnyObject() -> Any {
- return ["product": product,
- "price": price,
- "completed": completed
- ]
- }
Add Comment
Please, Sign In to add comment