swift - Firebase fetch data using .value observer is not working? -


i wan't fetch firebase data using .value observer, have object class named "object" , has 1 property named "test" of type string .

update : object class

public class object : nsobject{      var test  : string!  } 

this code :

import uikit import firebase  class viewcontroller: uiviewcontroller {     var ref : firdatabasereference!     var objarray = [object]()        override func viewdidload() {         super.viewdidload()         ref = firdatabase.database().reference().child("root")         loaddata()     }      func loaddata(){          ref.observe(.value, with: { (snapshot) in             let obj = object()             if let data = snapshot.value as? [string : anyobject]{                 obj.setvaluesforkeys(data)                 self.objarray.append(obj)                 print("%%%%%%% \(obj.test)")             }          })      }  } 

when use .value observer retrieve nothing !!, if use .childadded data retrieved ??

could 1 guide me if i'm doing wrong ?

update : enter image description hereadding firebase database image

you should looping on returned dictionary [string : anyobject] , then creating the corresponding object instances.

ref.observe(.value) { (snapshot) in     if let data = snapshot.value as? [string : anyobject] {         objectdata in data.values {             let obj = object()             obj.setvaluesforkeys(objectdata as! [string : anyobject])             self.objarray.append(obj)             print("%%%%%%% \(obj.test)")        }     } }                

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -