This is my solution for this JSON:
JSON:
{ "users" : { "-KWGdcdZD8QJSLx6rSy8" : { "name" : "dummy1", "visibility" : true }, "-KWGeGivZl0dH7Ca4kN3" : { "name" : "dummy2", "visibility" : false }, "-KWGeIvWHBga0VQazmEH" : { "name" : "dummy3", "visibility" : true } } }
SWIFT:
// Get only descendants with the attribute "visibility" = true
Database.database().reference().child("users").queryOrdered(byChild: "visibility").queryEqual(toValue: true).observeSingleEvent(of: .value, with: { (snapshot) in guard let dictionary = snapshot.value as? [String:Any] else {return} dictionary.forEach({ (key , value) in print("Key \(key), value \(value) ") }) }) { (Error) in print("Failed to fetch: ", Error) }
source share