Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Cloud Firestore无法检索文档或字段_Ios_Swift_Firebase_Google Cloud Firestore - Fatal编程技术网

Ios Cloud Firestore无法检索文档或字段

Ios Cloud Firestore无法检索文档或字段,ios,swift,firebase,google-cloud-firestore,Ios,Swift,Firebase,Google Cloud Firestore,我使用了Firebase文档提供的示例代码,它打印出了错误消息。我不知道问题是在代码中还是在数据库结构中,因为还有子集合。在本例中,我试图检索“Home Title”字段,但是我听说这是不可能的(我可能错了),所以我试图检索“Sample Wedding”文档,但没有任何效果。这是我第一次用Swift和Firestore编程项目 这是我的密码: let db=Firestore.Firestore() let docRef=db.集合(“婚礼”).文件(“婚礼样本”) docRef.getDoc

我使用了Firebase文档提供的示例代码,它打印出了错误消息。我不知道问题是在代码中还是在数据库结构中,因为还有子集合。在本例中,我试图检索“Home Title”字段,但是我听说这是不可能的(我可能错了),所以我试图检索“Sample Wedding”文档,但没有任何效果。这是我第一次用Swift和Firestore编程项目

这是我的密码:

let db=Firestore.Firestore()
let docRef=db.集合(“婚礼”).文件(“婚礼样本”)
docRef.getDocument{(文档,错误)位于
如果let document=document,则存在document{
让dataDescription=document.data().map(String.init(description:))??“nil”
打印(“文档数据:\(数据描述)”)
}否则{
打印(“文档不存在”)
}
以下是我的数据库结构:
]你可以这样试试

  let db = Firestore.firestore()
  db.collection("Weddings").document("Sample Wedding").getDocument { 
  (documentSnapshot, err) in
        if let err = err {
            print("Error getting documents: \(err)")
        } else {
            print("Document data: \(documentSnapshot)")
            if let title = documentSnapshot.get("Home Title") as? String {
            print(title)
           }
        }
    }

确切的位置和发生了什么错误?它打印出“文档不存在”,即使应该有一个。非常感谢!它工作!你知道我将如何显示一个字符串数组的字段吗?如果让title\u array=documentSnapshot.get(“主标题”)为?[String]{print(title\u array)}