【问题标题】:Why are print statements not executing in correct order?? Am I crazy or is Xcode?为什么打印语句没有按正确的顺序执行?我疯了还是 Xcode?
【发布时间】:2020-01-11 22:19:02
【问题描述】:

由于某种我无法弄清楚的原因,最后一个打印语句在第二个打印语句 (doc.data()) 之前执行。任何帮助将非常感激。在某些情况下,我正在尝试从 firestore 查询数据并将其中一些数据保存在 User 对象中。那么为什么这些打印语句会以错误的顺序执行。

let db = Firestore.firestore()
guard let uid = Auth.auth().currentUser?.uid else { return }

print("hello world")
db.collection("users").whereField("uid", isEqualTo: uid).getDocuments() { (querySnapshot, error) in
    if let error = error {
        print("Error finding user: \(error)")
    } else {
        for document in querySnapshot!.documents {
            print(document.data())
        }
    }
}

print("Am I crazy or is Xcode?")

【问题讨论】:

    标签: ios swift google-cloud-firestore


    【解决方案1】:

    仔细查看您的日志。 来自 firestore 的响应是异步的。 您的日志可能如下所示:

    hello world
    Am I crazy or is Xcode?
    user1
    user2
    user3

    【讨论】:

      猜你喜欢
      • 2021-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      相关资源
      最近更新 更多