Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. DataService.ds.REF_GAMES.queryOrdered(byChild: "team1").queryEqual(toValue: teamKey).observeSingleEvent(of: .value, with: { (snapshot) in
  2. if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
  3.  
  4. guard snapshot.exists() else {
  5. print("No Team Games Here")
  6. return
  7. }
  8.  
  9. for snap in snapshots {
  10. print("TeamVC - GAME: (snap)")
  11. if let gameDict = snap.value as? Dictionary<String, AnyObject> {
  12.  
  13. // Save unique key value for Team
  14. let key = snap.key
  15. let game = Game(gameKey: key, gameData: gameDict)
  16. self.teamGames.append(game)
  17. }
  18. }
  19. self.gameCollectionView.reloadData()
  20. }
  21. })
  22.  
  23. DataService.ds.REF_GAMES.queryOrdered(byChild: "team2").queryEqual(toValue: teamKey).observeSingleEvent(of: .value, with: { (snapshot) in
  24. if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
  25.  
  26. guard snapshot.exists() else {
  27. print("No Team Games Here")
  28. return
  29. }
  30.  
  31. for snap in snapshots {
  32. print("TeamVC - GAME: (snap)")
  33. if let gameDict = snap.value as? Dictionary<String, AnyObject> {
  34.  
  35. // Save unique key value for Team
  36. let key = snap.key
  37. let game = Game(gameKey: key, gameData: gameDict)
  38. self.teamGames.append(game)
  39. }
  40. }
  41. self.gameCollectionView.reloadData()
  42. }
  43. })
  44.  
  45. func uploadGames(teamKey : String, gameKey : String) {
  46. //Load team games from database based on key
  47. DataService.ds.REF_GAMES.queryOrdered(byChild: gameKey).queryEqual(toValue: teamKey).observeSingleEvent(of: .value, with: { (snapshot) in
  48. if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
  49.  
  50. guard snapshot.exists() else {
  51. print("No Team Games Here")
  52. return
  53. }
  54.  
  55. for snap in snapshots {
  56. print("TeamVC - GAME: (snap)")
  57. if let gameDict = snap.value as? Dictionary<String, AnyObject> {
  58.  
  59. // Save unique key value for Team
  60. let key = snap.key
  61. let game = Game(gameKey: key, gameData: gameDict)
  62. self.teamGames.append(game)
  63. }
  64. }
  65. self.gameCollectionView.reloadData()
  66. }
  67. })
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. self.uploadGames(teamKey: playerTeamKey, gameKey: "team1Key")
  76. self.uploadGames(teamKey: playerTeamKey, gameKey: "team2Key")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement