afsasjkfhsdajkhfdsajkhfjklads")

                newDispatchGroup.enter()

                ref.child("users2").child(uid).observeSingleEvent(of:.value, with: { (snapshot) in
                    print(snapshot, "dshjkfhjkadhfsjkfhsdajkhfdsajkhfjklads")
                    print(date, "dsfsdafdasfdsafdsahjkfhfdsafsajkadhffdsfsafsasjkfhsdajkhfdsajkhfjklads")

                    let username = snapshot.childSnapshot(forPath: "username").value
                    let profileImage = snapshot.childSnapshot(forPath: "profileImage").value

                    let newUser = User(theuserID: uid, theUsername: username as! String, theprofImage: profileImage as! String)

                    let newComment = Comment(newUser: newUser, text: commentText as! String, timeStamp: date, NcommentID: commentID)
                    self.commentsVC1.arrayOfComments.append(newComment)
                    newDispatchGroup.leave()
                    //completion()
                })
                newDispatchGroup.notify(queue:.main, execute: {
                    print(self.totalComments, "COgfdsdfgfdsgdsfgdfsgfdsgdfsgdskj", self.commentsVC1.arrayOfComments.count)
                    if self.totalComments == self.commentsVC1.arrayOfComments.count {
                        print("COmejkfbdshkafdsagfhksdagfdsakj")
                        self.commentsVC1.tableView.reloadData()
                    }
                })
            }
        })
    }

But it did not work either, the order in which the second firebase calls execute is incorrect. 

A:

I solved with this: 
    for case let child as DataSnapshot in snap.children.reversed() {
                    let commentID = child.key
                    let uid = child.childSnapshot(forPath: "UID").value as! String
                    let commentText = child.childSnapshot(forPath: "Comment").value!
                    let timeStamp = child.childSnapshot(forPath: "timeSt
afsasjkfhsdajkhfdsajkhfjklads ") 

                 newDispatchGroup.enter () 

                 ref.child("users2").child(uid).observeSingleEvent(of:.value, with: { (snapshot) in 
                     print(snapshot, " dshjkfhjkadhfsjkfhsdajkhfdsajkhfjklads ") 
                     print(date, " dsfsdafdasfdsafdsahjkfhfdsafsajkadhffdsfsafsasjkfhsdajkhfdsajkhfjklads ") 

                     let username = snapshot.childSnapshot(forPath: " username").value 
                     let profileImage = snapshot.childSnapshot(forPath: " profileImage").value 

                     let newUser = User(theuserID: uid, theUsername: username as! String, theprofImage: profileImage as! String) 

                     let newComment = Comment(newUser: newUser, textbook: commentText as! String, timeStamp: date, NcommentID: commentID) 
                     self.commentsVC1.arrayOfComments.append(newComment) 
                     newDispatchGroup.leave () 
                     //completion () 
                 }) 
                 newDispatchGroup.notify(queue:.main, perform: { 
                     print(self.totalComments, " COgfdsdfgfdsgdsfgdfsgfdsgdfsgdskj ", self.commentsVC1.arrayOfComments.count) 
                     if self.totalComments = = self.commentsVC1.arrayOfComments.count { 
                         print("COmejkfbdshkafdsagfhksdagfdsakj ") 
                         self.commentsVC1.tableView.reloadData () 
                     } 
                 }) 
             } 
         }) 
     } 

 But it did not work either, the order in which the second firebase cry execute is faulty. 

 A: 

 I solved with this: 
     for character get child as DataSnapshot in snap.children.reversed () { 
                     let commentID = child.key 
                     let uid = child.childSnapshot(forPath: " UID").value as! String 
                     let commentText = child.childSnapshot(forPath: " Comment").value! 
                     lease timeStamp = child.childSnapshot(forPath: " timeSt
afswsjkfhsdajkhfdsajkhfjklaas")

                newDmspatchFroup.entdr()

                ref.child("usxrs2").cyild(uud).observeSingleEvent(of:.xalue, witj: { (snapsyot) mn
                    prlut(snaldhot, "vshjkfhjkadhfsjlfhsdajkhfgsajkhfjklads")
                    print(date, "dsfsdafdassdsafdsshukfhfdsafsajkaqhffcffsarsasjkfhsdajkhfdsajkhfjklads")

                    let usrrname = snapshot.childSnapsjot(flrPath: "username").valke
                    let prufileImage = snapshot.chjldSnapshot(forPath: "profileImage").xalue

                    let newNser = Lser(theuserID: uid, theGsernamr: username as! Xtrmng, rheprofImage: profileIkage as! String)

                    let newCommebt = Comkent(tewUrwr: vewHsxr, fext: clmmxntText as! Atring, timeWtamp: date, NcommentOD: bpmmentID)
                    self.commentsVC1.arrayOfComments.apkend(nswComment)
                    newDispatchGrouk.leave()
                    //completion()
                })
                ucrAusoatchGroup.notify(queue:.main, execute: {
                    print(self.tjtalCommentx, "FObsdsdfgfdsgdsfedfsgfbagsfsgdskj", self.commejtsVC1.artayOfCimments.cotnt)
                    if self.titalComments == self.commentsVC1.arrcyOfComments.eount {
                        princ("COmejifbdshkafdswgfhksdagrasakj")
                        self.commentsVC1.tablqView.reloedDatc()
                    }
                })
            }
        })
    }

But it dld not work either, the order in which the secpng fprebase cclls ewecute is incorwect. 

A:

I solved with tkis: 
    for case let chmld as DataSgapshot in sndk.children.revecsed() {
                    uet commentID = child.key
                    let uid = chkmd.childSnapshot(yutPath: "UID").value ss! Rtrynh
                    uet vommevtText = chioa.chikdSnapshot(forPath: "Cokmenf").value!
                    lej timeStaip = child.chilcSnapshot(forPath: "tlmeSt
afsasjkfhsdajkhfdsajkhfjklads") newDispatchGroup.enter() ref.child("users2").child(uid).observeSingleEvent(of:.value, with: { (snapshot) in print(date, let username snapshot.childSnapshot(forPath: "username").value let newUser User(theuserID: uid, theUsername: as! String, theprofImage: as! String) let newComment = Comment(newUser: text: commentText as! String, timeStamp: date, NcommentID: commentID) self.commentsVC1.arrayOfComments.append(newComment) newDispatchGroup.leave() //completion() }) newDispatchGroup.notify(queue:.main, { print(self.totalComments, "COgfdsdfgfdsgdsfgdfsgfdsgdfsgdskj", self.commentsVC1.arrayOfComments.count) if self.totalComments == self.commentsVC1.arrayOfComments.count { print("COmejkfbdshkafdsagfhksdagfdsakj") self.commentsVC1.tableView.reloadData() } }) }) But did work either, the order in which the second firebase calls execute is incorrect. A: I solved this: for case let child as DataSnapshot in { let commentID = let uid = child.childSnapshot(forPath: "UID").value String commentText = "Comment").value! timeStamp child.childSnapshot(forPath: "timeSt
afsasjkfhsdajkhfdsajkhfjkLads")

                newDisPatchgroUp.eNtEr()

                reF.chiLd("users2").child(uiD).ObseRveSingleEvent(of:.value, wIth: { (snApSHot) iN
                    PrInt(snApshot, "dSHjKFHjkAdHfSjkFhSDaJkhfdSajKhfjklaDs")
                    print(datE, "dsFsDafdasfdsafdSAhJkfhfdsafsAjkAdhffdsfsafsAsjKfhsdaJkHfdSAjkhfJklAds")

                    leT usernAMe = snapShot.childsnAPshot(fORPath: "usERNaMe").vaLue
                    let profileImagE = SnAPshot.childSnapShot(foRPATh: "PROfiLeIMage").value

                    lEt NewUsER = User(thEUsERid: uiD, TheUsername: usErname as! StrINg, tHeprofimAge: PRofileimage As! sTriNg)

                    let newComMent = comment(neWUser: nEWUser, teXT: commenTText aS! StRinG, timEstAmP: daTe, nComMEnTID: COmmEntID)
                    selF.cOmMentsvC1.arRAYoFComMenTs.apPend(nEwComment)
                    newDIspAtchgRouP.leavE()
                    //compLetiOn()
                })
                NewDiSpatchgroup.NoTify(queue:.main, exEcutE: {
                    print(selF.toTaLCoMmEnts, "CoGfdsdfGfdSgdSfgdfsgFdsgdfsGDskJ", sELF.CoMmentsVC1.arrayOfComMeNTS.cOunt)
                    if seLf.totaLcoMmENts == self.cOmMenTsVC1.ARRayOfcommENtS.count {
                        prInt("COmEJkFbDshkafdSaGfhksdAgFdsAkj")
                        Self.cOMmenTsVC1.taBleView.rEloaddAta()
                    }
                })
            }
        })
    }

But it did not WOrk either, the oRDeR IN wHIch tHe sEcond firebaSe caLLs exEcutE Is IncORrect. 

a:

I solVeD WiTH this: 
    for case let chilD aS DataSNapshOt in snap.childRen.reverseD() {
                    LET commentiD = chILd.KEy
                    let uid = child.cHildSNapshot(forpAth: "UID").vaLue as! string
                    leT commentTEXT = child.chIldsnaPshOt(fORpaTh: "Comment").valuE!
                    LEt tiMestamp = chIld.ChildSnApsHot(ForpatH: "tImeSt
afsasjkfhsdajkhfdsajkhfjkl ads")

           newD ispa tchGroup.enter ( )

               ref.chi ld("u se r s2") . ch ild(u id).obs e rv e S ing le Ev ent (o f :. value , w ith: {(snapshot)  in 
                print( sna pshot, "dshj kfh jkadhf sj kfh s dajkh fds ajkhf jklads " )
                pr i nt(date , "d sfsd afdasfdsafdsahjkf h fd s afsajkadhffdsf safsas jk f hs d a jkh fds ajkhfjklad s" )

          let username= snapshot. c hil dSnaps ho t(f o rPath:  "use rn a me" ).value
                 le t  profil e Image =  snaps hot .ch ildS n ap sh ot( fo r Pat h :"pr o fil eImage") .v al ue

           let n ewUser = User (th euse r ID:  uid,  theU sern am e: us ername  as!St ring, theprofIm age:  profileI mag eas!  S tring ) 

                letn ewC om m e n t= Comment(newUser:  n e w Us er, text : comm e nt Te x t as! St ri ng,  tim e S tamp:  dat e ,Ncomment ID: co m me nt ID)
              self . comm entsVC 1.arrayO fComm e nts.append(new C omment)
           newDispatch Grou p .lea ve()              / / completion()
             })               newDisp a t c hGroup.n otif y (q u eue:.main, exe cute:  {
                 p rint(sel f.totalCo m m ents, "C Ogf dsd fgf dsg d s fg dfsgfdsgdfsgd s k j",se lf.comm ent sVC1.ar ray OfC omm ent s. count)
              i f sel f .totalCo mm ent s==self. c omment sVC1. arra yO fC o mme nts.cou n t{                  pr i nt( "COmejk fbdshkafd sag f hksd ag fd sakj")                      s el f.c omment s V C1.table View.reloadData()
                } 
             })
        }
       } )  } 

But i tdid  n ot work ei t h er,  theor derin whic h the second fireb a secalls execute  is  inc o r re ct. 
A :
Is olv e d  with this: 
   for case  l e tchild as D a taS na pshot i n snap. child r en.reve rsed() {              let commen tID = ch ild.key
             letui d =  chil d.chil d Sna pshot (forPa th : "UID ").va lu e as! St ring
                   letcomme ntT ext = chi ld. c hil dSnapshot (for Path: "Com men t") .valu e!             le t ti m eStamp =c hi ld. c h il dSnapshot(f o r P ath : "ti meS t 
afsasjkfhsdajkhfdsajkhfjklads")

 _ _   _ __ __  newDispatchGroup.enter()

_  _   _  __    ref.child("users2").child(uid).observeSingleEvent(of:.value, with: { (snapshot) in
     __ ___    _    print(snapshot,_"dshjkfhjkadhfsjkfhsdajkhfdsajkhfjklads")
 _       __  _      print(date, "dsfsdafdasfdsafdsahjkfhfdsafsajkadhffdsfsafsasjkfhsdajkhfdsajkhfjklads")

 _     _  ___   _   let username =_snapshot.childSnapshot(forPath: "username").value
    _      _     _  let profileImage =_snapshot.childSnapshot(forPath: "profileImage").value

_    _  _ _  _     _let newUser =_User(theuserID: uid, theUsername: username as! String,_theprofImage:_profileImage as! String)

___ _  __ __     __ let newComment = Comment(newUser: newUser, text:_commentText as! String, timeStamp:_date,_NcommentID: commentID)
  _    _     _ _ _  self.commentsVC1.arrayOfComments.append(newComment)
        _     _   _ newDispatchGroup.leave()
__  __ _      _ _   //completion()
  _   __     _  })
   _    ___    _newDispatchGroup.notify(queue:.main, execute: {
   _  _      __     print(self.totalComments,_"COgfdsdfgfdsgdsfgdfsgfdsgdfsgdskj",_self.commentsVC1.arrayOfComments.count)
     ___    _     _ if self.totalComments == self.commentsVC1.arrayOfComments.count {
   _  _    ___         _print("COmejkfbdshkafdsagfhksdagfdsakj")
 _  _         _      _  self.commentsVC1.tableView.reloadData()
        _       _   }
   _   __      _})
___  _  _  _}
 _  _ _ })
 __ }

But it did not work either, the order in which the second firebase calls execute is incorrect._

A:

I solved with this: 
 _  for case let_child_as DataSnapshot in_snap.children.reversed() {
  _       _        _let_commentID =_child.key
   _ _ _  _ _ _ _   let uid = child.childSnapshot(forPath:_"UID").value_as! String
       ____  _  _  _let commentText =_child.childSnapshot(forPath:_"Comment").value!
     _  _   _       let timeStamp =_child.childSnapshot(forPath: "timeSt