arrays - Retrieving firebase data from a nested loop -


im stuck in weird situation. have users node, , have following , artists node.

users  r4mulkuhyjd1sqxwp8l7ualjh5h2   email:     "nusu@gmail.com"   provider:     "firebase"   username:     "alper" following   r4mulkuhyjd1sqxwp8l7ualjh5h2    -ktvg3homx-su-uhhr55:  1    -ktvgo74fsoomqblblbr:  1    -ktvqyds-974cquwee6d: 1  artists   -ktvg3homx-su-uhhr55     artistimageurl:  "https://lastfm-img2.akamaized.net/i/u/64s/f657d..."     artistname: "skid row" 

what want is: want find artists user follows, , id's getting artists infos. how trying this:

fileprivate func fetchfollowedartists(withid id: string){     let ref = database.database().reference().child("following")     ref.child(id).observe(.value) { (snapshot) in         self.followedartistscount = snapshot.childrencount         let attributedtext = nsmutableattributedstring(string: "\(self.followedartistscount ?? 0)\n", attributes: [nsattributedstringkey.font: uifont.systemfont(ofsize: 14, weight: uifont.weight.light)])         attributedtext.append(nsattributedstring(string: "artists", attributes: [nsattributedstringkey.foregroundcolor: uicolor.lightgray, nsattributedstringkey.font: uifont.systemfont(ofsize: 14)]))         self.artistcount.attributedtext = attributedtext         if let dict = snapshot.value as? [string:any] {             dict.foreach({ (key,val) in                 print("artist id: \(key)")                 database.database().reference().child("artists").child(key).observe(.value, with: { (snapshot2) in                     if let dict = snapshot2.value as? [string:any] {                         print(dict["artistname"] as! string)                         self.artistname.append(dict["artistname"] as! string)                         print(self.artistname)                         self.tableview.insertrows(at: [indexpath(row:self.artistimage.count,section:0)], with: uitableviewrowanimation.automatic)                     }                  })              })         }     } 

at first time it's ok. when add new child following mess up.enter image description here

it adds old array while foreach loop lasts.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -