swift - Retrieve Data with second .child method from Firebase Database -


to explain issue need see database structure first:

datastructure

what want retrieve name node "1000" that's did far:

var datref: databasereference!     datref = database.database().reference()     datref.child("qrbereich").child("1000").observe(.childadded, with: { (snapshot) in          if let dict = snapshot.value as? [string: anyobject]{              let qrbar = qrbar(dictionary: dict)             qrbar.setvaluesforkeys(dict)              qrbarname.append(qrbar.name!) }     }          , withcancel: nil) 

but gives me empty array. when delete ".child("1000")" receive names nodes 1000(barracuda) , 2000(deluxxe). need name "barracuda" node 1000.

qrbar model , written follow:

import foundation class qrbar: nsobject { var name: string?  init(dictionary: [string: any]) {     self.name = dictionary["name"] as? string ?? ""   } } 

it looks need .value event:

datref.child("qrbereich").child("1000").observe(.value, with: { (snapshot) in 

you'd use .childadded if you're listening children under qrbereich.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -