swift3 - Fetching images from Firebase child -


everyone. have troubles fetching chunk of images child in firebase database. doing ios project , using swift 3 , xcode. basically, after all, "image" variable returns "nil" please, me if can. here code using:

let ref = firdatabase.database().reference().child("menu")         ref.observesingleevent(of: .value, with: { (snapshot) in             if let dictionary = snapshot.value as? [string: anyobject] {                 let image = dictionary["foodimageurl"] as? string                 print(image any) // returns nil 

and example of database structure

enter image description here

i need fetch "foodimageurl" children menu node

your snapshot.value list of sub items menu, not details info of each node, have use foreach, , inside each node, use dictionary["foodimageurl"] as? string image

try this

let ref = firdatabase.database().reference().child("menu")     ref.observesingleevent(of: .value, with: { (snapshot) in         rest in snapshot.children.allobjects as! [firdatasnapshot] {             if let dictionary = rest.value as? [string: anyobject]{                 let image = dictionary["foodimageurl"] as? string                 print(image any)             }          } 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -