Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //will show the vents that a user is attending
- static func Events(for user: User, completion: @escaping ([Event]) -> Void)
- {
- var currentEvents = [Event]()
- //Getting firebase root directory
- let ref = Database.database().reference().child("users").child(user.uid).child("Attending")
- ref.observe(.value, with: { (snapshot) in
- // print(snapshot)
- // guard snapshot.children.allObjects is [DataSnapshot] else {
- // return completion([])
- // }
- guard let eventDictionary = snapshot.value as? [String: Any] else {
- return completion([])
- }
- // print(snapshot)
- let dispatchGroup = DispatchGroup()
- eventDictionary.forEach({ (key,value) in
- // print(key)
- // print(value)
- EventService.show(forEventKey: key , completion: { (event) in
- dispatchGroup.enter()
- AttendService.isEventAttended(event, byCurrentUserWithCompletion: { (isAttended) in
- event?.isAttending = isAttended
- dispatchGroup.leave()
- })
- currentEvents.append(.init(currentEventKey: key , dictionary: (event?.eventDictionary)!))
- })
- })
- dispatchGroup.notify(queue: .main, execute: {
- completion(currentEvents)
- })
- })
- }
Add Comment
Please, Sign In to add comment