gpt4 book ai didi

ios - Swift Firebase - 使用文档 UID 获取当前用户以填充列表

转载 作者:行者123 更新时间:2023-11-28 07:49:16 24 4
gpt4 key购买 nike

所以我已经在我的 android 应用程序上完成了这个(并且它有效),用集合中的文档名称填充列表

  db.collection("usersAuth/${FirebaseAuth.getInstance().uid!!}/KitLists")
.addSnapshotListener(EventListener<QuerySnapshot> { value, e ->
if (e != null) {
Log.w("TAG", "Listen failed.", e)
return@EventListener
}

for (document in value.documents) {
val data = document

val kitName = data.id

firstKitList.add(kitName)

}

mainListViewAdapter.notifyDataSetChanged()
})

我正在尝试在我的 iOS 版本上做同样的事情,但我不知道哪里出了问题

override func viewWillAppear(_ animated: Bool) {

setListener()

}

func setListener() {

db.collection("usersAuth/\(String(describing: Auth.auth().currentUser))/KitLists")
.addSnapshotListener { (snapshot, error ) in
if let err = error {
debugPrint("Error fetching docs: \(err)")
} else {
guard let snap = snapshot else {return}
for document in snap.documents {
let data = document.data()
let kitListName = data["KitLists"] as? String


let newLists = KitList(kitListName: kitListName!)
self.lists.append(newLists)
}


self.tableView.reloadData()
}
}

}

有什么想法吗?谢谢

-- 编辑

Firestore

Firestore2

最佳答案

需要从currentUser获取uid,例如:

if let userId = Auth.auth().currentUser.uid {
db.collection("usersAuth").document(userId).collection("KitLists")
.addSnapshotListener { (snapshot, error ) in
//...
}

获取 KitLists documentId

for document in snap.documents {
let documentName = document.documentID // <--- This
let newLists = KitList(kitListName: documentName)
self.lists.append(newLists)
}

关于ios - Swift Firebase - 使用文档 UID 获取当前用户以填充列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50116956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com