【发布时间】:2018-05-24 12:59:39
【问题描述】:
我使用 Firestore 作为我的 iOS 应用后端。
我有这样的结构......
/users
/userId
name:"Bob"
/likedPosts //this is the object, not a collection
"post1":true
"post2":true
因此 - 我试图在用户的个人资料上显示“likedPosts”(帖子类)。
我不知道如何查询结果以获取用户喜欢的帖子,然后查询以显示每个帖子。
func getUserNameAndInfo() {
if let user = Auth.auth().currentUser {
// User is signed in
// References to firebase
let userFS = Firestore.firestore().collection("users")
// Set the navigation title to users name
userFS.document(user.uid).getDocument { (document, error) in
if let userInfo = document {
let firstName = userInfo["firstName"] as! String
let lastName = userInfo["lastName"] as! String
let likedPostsDictionary = userInfo.data()["likedPosts"] as! NSDictionary
for (postId, _) in likedPostsDictionary {
self.userLikedPostsArray.append(postId as! String)
print(self.userLikedPostsArray)
}
} else {
print("User name does not exist")
}
}
}
所以我可以获取帖子的所有 ID。但我对如何查询 Firestore 以获取这些 Id 的信息感到困惑。
【问题讨论】:
-
您是如何将对象中的数据存储到 Firestore 中的。我还想以对象形式存储数据,例如 collection/document/collection/doument/invitess1(object) :金额:20,电话号码:1234567890 ..........你能告诉我如何存储吗数据到 Firestore
标签: ios swift firebase firebase-realtime-database google-cloud-firestore