これは初めてのスタックオーバーフローを使用しています。私は私のプログラムが移動する前にクエリタスクが完了するまで待つようにしていますが、正しく動作することはありません。私はデバッグのためにprintステートメントを入れました。 2番目と3番目の印刷は常に最初の印刷の前に行われます。私はdispatch_syncをよく理解していないと思います。どんな助けでも大歓迎です!迅速にdispatch_syncを使用するにはどうすればよいですか?
let concurrentQueue = dispatch_queue_create(
"com.x.TinderClone.queue", DISPATCH_QUEUE_CONCURRENT)
dispatch_sync(concurrentQueue) {
usersRef.queryOrderedByChild("gender").queryEqualToValue(userInterestedIn).observeSingleEventOfType(.Value, withBlock: {snapshot in
for child in snapshot.children {
let uid = child.key!!
let gender = child.value!!["gender"] as! String
let id = child.value!!["id"] as! String
let interestedInWomen = child.value!!["interestedInWomen"] as! Bool
let name = child.value!!["name"] as! String
let potentialMatch = User(uid: uid, gender: gender, id: id, interestedInWomen: interestedInWomen, name: name)
listOfPotentialMatches.append(potentialMatch) //add the user struct to the array
}
print("First") // First print
// ...
}) { (error) in
print(error.localizedDescription)
}
print("Second") // Second Print
}
print("Third") //Third print