Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. struct GroceryList {
  2.  
  3. let ref: DatabaseReference?
  4. let key: String
  5. let groceryListName: String
  6.  
  7. init(groceryListName: String, key: String = "") {
  8. self.ref = nil
  9. self.key = key
  10. self.groceryListName = groceryListName
  11. }
  12.  
  13. init?(snapshot: DataSnapshot) {
  14. guard
  15. let value = snapshot.value as? [String: AnyObject],
  16. let groceryListName = value["groceryListName"] as? String else { return nil }
  17.  
  18. self.ref = snapshot.ref
  19. self.key = snapshot.key
  20. self.groceryListName = groceryListName
  21. }
  22.  
  23. func toAnyObject() -> Any {
  24.  
  25. return ["groceyListName": [Items.toAnyObject]]
  26. }
  27.  
  28. struct Items {
  29.  
  30. let ref: DatabaseReference?
  31. let key: String
  32. let product: String
  33. let price: String
  34. var completed: Bool
  35.  
  36.  
  37. init(product: String, price: String, completed: Bool, key: String = "") {
  38. self.ref = nil
  39. self.key = key
  40. self.product = product
  41. self.price = price
  42. self.completed = completed
  43.  
  44. }
  45.  
  46. init?(snapshot: DataSnapshot) {
  47. guard
  48. let value = snapshot.value as? [String: AnyObject],
  49. let product = value["product"] as? String,
  50. let price = value["price"] as? String,
  51. let completed = value["completed"] as? Bool else { return nil }
  52.  
  53. self.ref = snapshot.ref
  54. self.key = snapshot.key
  55. self.product = product
  56. self.price = price
  57. self.completed = completed
  58. }
  59.  
  60. func toAnyObject() -> Any {
  61. return ["product": product,
  62. "price": price,
  63. "completed": completed
  64. ]
  65. }
Add Comment
Please, Sign In to add comment