【发布时间】:2016-09-03 10:36:09
【问题描述】:
我正在尝试编写一个函数,该函数将返回我所有工作人员的数组,但它在从 firebase 检索数据之前返回
这是我的代码:
func getWorkersList() -> ([Worker])
{
let workersInfoRef = ref.childByAppendingPath("countries/\(userCountry)/cities/\(userCity)/workers/\(workFieldToRecieve)/")
var workerList = [Worker]()
workersInfoRef.queryOrderedByChild("name").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
print(snapshot.childrenCount)
for rest in snapshot.children.allObjects as! [FDataSnapshot]{
let workerInfo = Worker(uid: rest.value["uid"] as! String, name: rest.value["name"] as! String, city: rest.value["city"] as! String, profession: rest.value["profession"] as! String, phone: rest.value["phone"] as! String, email: rest.value["email"] as! String, country: rest.value["country"] as! String)
workerList.append(workerInfo)
}
}) { (error) in
print(error.description)
}
print(workerList.count)
return workerList
}
【问题讨论】:
标签: swift firebase asynchronous firebase-realtime-database