Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataService.ds.REF_GAMES.queryOrdered(byChild: "team1").queryEqual(toValue: teamKey).observeSingleEvent(of: .value, with: { (snapshot) in
- if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
- guard snapshot.exists() else {
- print("No Team Games Here")
- return
- }
- for snap in snapshots {
- print("TeamVC - GAME: (snap)")
- if let gameDict = snap.value as? Dictionary<String, AnyObject> {
- // Save unique key value for Team
- let key = snap.key
- let game = Game(gameKey: key, gameData: gameDict)
- self.teamGames.append(game)
- }
- }
- self.gameCollectionView.reloadData()
- }
- })
- DataService.ds.REF_GAMES.queryOrdered(byChild: "team2").queryEqual(toValue: teamKey).observeSingleEvent(of: .value, with: { (snapshot) in
- if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
- guard snapshot.exists() else {
- print("No Team Games Here")
- return
- }
- for snap in snapshots {
- print("TeamVC - GAME: (snap)")
- if let gameDict = snap.value as? Dictionary<String, AnyObject> {
- // Save unique key value for Team
- let key = snap.key
- let game = Game(gameKey: key, gameData: gameDict)
- self.teamGames.append(game)
- }
- }
- self.gameCollectionView.reloadData()
- }
- })
- func uploadGames(teamKey : String, gameKey : String) {
- //Load team games from database based on key
- DataService.ds.REF_GAMES.queryOrdered(byChild: gameKey).queryEqual(toValue: teamKey).observeSingleEvent(of: .value, with: { (snapshot) in
- if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
- guard snapshot.exists() else {
- print("No Team Games Here")
- return
- }
- for snap in snapshots {
- print("TeamVC - GAME: (snap)")
- if let gameDict = snap.value as? Dictionary<String, AnyObject> {
- // Save unique key value for Team
- let key = snap.key
- let game = Game(gameKey: key, gameData: gameDict)
- self.teamGames.append(game)
- }
- }
- self.gameCollectionView.reloadData()
- }
- })
- }
- self.uploadGames(teamKey: playerTeamKey, gameKey: "team1Key")
- self.uploadGames(teamKey: playerTeamKey, gameKey: "team2Key")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement