我在while循环中调用以下函数,但即使使用dispatch_group,异步代码也不会运行。有谁知道我可能做错了什么? *我试图基本上获取while循环以等待异步代码在继续之前执行。
override func viewDidAppear(animated: Bool) {
if(ended != true) {
if(count2 < 2) {
print("current count is < 2")
} else {
var playRef = ref.child("LiveGames").child("05-25-17").child("RedSox")
asyncCall(playRef, ended: ended, count: count2)
}
print("successful delay")
count2++
//playIsntThere()
}//this is where the else loop ends
count2++
}
func asyncCall(ref:FIRDatabaseReference, ended:Bool, count:Int) {
var count2 = count
let myGroup = dispatch_group_create()
dispatch_group_enter(myGroup)
ref.child(String(count2-2)).observeSingleEventOfType(.Value, withBlock: { (snapshot2) in
var hitterRef = snapshot2.childSnapshotForPath("/Hitter")
var pitcherRef = snapshot2.childSnapshotForPath("/Pitcher")
pitcherEra.text = String(pitcherRef.childSnapshotForPath("/ERA").value!)
})
dispatch_group_leave(myGroup)
dispatch_group_notify(myGroup, dispatch_get_main_queue()) {
print("code completed")
}
print("successful delay")
count2++
}