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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -