【发布时间】:2020-04-17 12:25:17
【问题描述】:
我正在从我的 Firebase 数据库中获取信息,其工作方式如下:
let docRef = db.collection("users").document(AccessToken.current!.userID)
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
print("name: \(dataDescription)")
print(document["name"])
print(document["ProfilePicURL"])
} else {
print("Document does not exist")
}
}
但我的数据库看起来像:
]1
我有什么简单的方法可以访问它吗?
【问题讨论】:
-
你分享的代码有什么问题?
-
对不起,我更新了数据库以更好地反映问题。所以我可以使用上面的代码访问 name: 和 profilePicURL,在 profilePicURL 中我可以整体接收“数据”,但数据的第一个字段是高度。所以问题是我将如何访问它,我需要重新循环还是可以访问字段中的字段?
-
当你请求一个作为对象的字段时,你会得到一个字典。然后,您可以像处理 Swift 中的任何其他字典一样处理其中的任何子字段。
标签: swift firebase google-cloud-firestore