Firebase 迅捷+;Firestore-无法访问Firestore中的字段

Firebase 迅捷+;Firestore-无法访问Firestore中的字段,firebase,google-cloud-firestore,swiftui,Firebase,Google Cloud Firestore,Swiftui,试图访问Firestore中的特定字段,但似乎无法找到它。在我的文档中,我有一张这样的地图: 下面是我的代码。不知什么原因,小时归零。我尝试了很多不同的方法,包括[“notificationTime”][“hour”],但似乎无法理解。有什么想法吗?谢谢 self.db.collection("routines").whereField("name", isEqualTo: routineName).getDocuments() { (querySnap

试图访问Firestore中的特定字段,但似乎无法找到它。在我的文档中,我有一张这样的地图:

下面是我的代码。不知什么原因,小时归零。我尝试了很多不同的方法,包括[“notificationTime”][“hour”],但似乎无法理解。有什么想法吗?谢谢

self.db.collection("routines").whereField("name", isEqualTo: routineName).getDocuments() { (querySnapshot, err) in
        if let err = err {
            print ("Error getting documents: \(err)")
        } else {
            for document in querySnapshot!.documents {
                let hour = document.data()["notificationTime.hour"]
                print(hour)
                return
             }
        }
    }

要从地图读取数据,请使用以下方法:

let db=Firestore.Firestore()
db.collection(“例程”).whereField(“name”,isEqualTo:routineName).getDocuments(){(querySnapshot,err)在
如果让err=err{
打印(“获取文档时出错:\(错误)”)
} 
否则,如果让querySnapshot=querySnapshot{
对于querySnapshot.documents中的文档{
让结果=document.data()
如果让notificationTime=结果[“notificationTime”]作为?[字符串:任意]{
设小时=通知时间[“小时”]为?Int??0
设分钟=通知时间[“分钟”]为?Int??0
//…进一步处理您的数据
}
}
}
}

话虽如此,我还是建议研究
Timestamp
s来存储与日期时间相关的数据。有关详细信息,请参阅。

要从地图读取数据,请使用以下方法:

let db=Firestore.Firestore()
db.collection(“例程”).whereField(“name”,isEqualTo:routineName).getDocuments(){(querySnapshot,err)在
如果让err=err{
打印(“获取文档时出错:\(错误)”)
} 
否则,如果让querySnapshot=querySnapshot{
对于querySnapshot.documents中的文档{
让结果=document.data()
如果让notificationTime=结果[“notificationTime”]作为?[字符串:任意]{
设小时=通知时间[“小时”]为?Int??0
设分钟=通知时间[“分钟”]为?Int??0
//…进一步处理您的数据
}
}
}
}
话虽如此,我还是建议研究
Timestamp
s来存储与日期时间相关的数据。有关详细信息,请参阅。

是否可以记录document.data()?是否可以记录document.data()?