我正在尝试在Firebase中获得一个孩子的孩子内部的值,并将该值存储到变量中。我认为我的路径不正确,因为每当我运行我的代码时,Xcode都会运行并命中
childRef.child(uidArray[incLoop]).observeSingleEvent(of: .value,
with: {(snap) in.. but doesn't run the code inside the function.
uidArray contains the uid of the users. How can I query the user's age?
下面是我在Firebase中的数据结构(我也在使用Geofire)
{
"Users" : {
"9n35bgJUZiYJVhnrcTJ5" : {
"Age" : 21,
"Strength" : 150,
"g" : "9q8yywdq7v",
"l" : [ 37.785834, -122.406417 ]
},
"bW3mGneMy7DkBbElCXXb" : {
"Age" : 21,
"Strength" : 150,
"UID" : "bW3mGneMy7DkBbElCXXb",
"g" : "9q8yywdq7v",
"l" : [ 37.785834, -122.406417 ]
}
},
"firebase-hq" : {
"g" : "7zzzzzzzzz",
"l" : [ 0, 0 ]
}
}
let childRef = Database.database().reference().child("Users")
childRef.child(uidArray[incLoop]).observeSingleEvent(of: .value,
with: {(snap) in
print(snap)
if let snapDict = snap.value as? [String:AnyObject]{
let age = snapDict["Age"] as! Int
print(String(age))
print("Done with Age")
}
})
}