如何下载Firebase结果?

时间:2016-10-23 19:50:49

标签: firebase firebase-realtime-database swift3 ios10

我在完成块中包含以下内容:

dbRef.child("Employees").queryOrdered(byChild: "deptid").queryEqual(toValue: "100").observe(.childAdded, with: {
  snapshot in
  //add each result to an array

问题是每个结果都会触发完成。我需要在所有结果下载后触发,这意味着阻止。我怎么能这样做呢?

1 个答案:

答案 0 :(得分:3)

尝试更改为: -

dbRef.child("Employees").queryOrdered(byChild: "deptid").queryEqual(toValue: "100").observeSingleEvent(of : .value, with:{ snapshot in
   if let snapDict = snapshot.value as? [String:AnyObject]{

        for each in snapDict{

              let deptID = each.value["deptid"] as! String

        }
   }
})