【发布时间】:2021-02-27 02:43:24
【问题描述】:
大家好,我正在使用 Firebase - Firestore 来保存数据。我刚刚创建了一个数据库调用,它返回一个Date,我从中提取小时和分钟。
小时和分钟必须保存在带有元组的array 中。
一切似乎都正常,但是当我在 clousure 之外阅读我的 array 时,它的值始终为零。
我还需要在 Firestore 查询方法之外读取array 的内容..
谁能帮我解决这个问题?
private var timeArray: [(Int, Int)] = []
private func getReservations() -> Void {
Service.Database.reservationRoot.whereField("date", isGreaterThan: Date()).getDocuments() { (querySnapshot, error) in
guard error == nil else { fatalError("Errore durante il recupero delle prenotazioni \(error!.localizedDescription)") }
for document in querySnapshot!.documents {
if let timestamp = document["date"] as? Timestamp {
let hour = timestamp.dateValue().component(.hour)
let minute = timestamp.dateValue().component(.minute)
self.timeArray.append((hour, minute))
// The array count is 2
print(self.timeArray.count)
}
}
}
// The array count is 0
print(self.timeArray.count)
}
【问题讨论】:
标签: ios swift firebase google-cloud-firestore