嘗試獲取用戶時,我收到錯誤訊息:“'DocumentSnapshot 型別的值?' 沒有成員'檔案'”。錯誤發生在以“let uid ....”開頭的行上。
import SwiftUI
import Firebase
// Global Refernce
let ref = Firestore.firestore()
func fetchUser(uid: String,completion: @escaping (UserModel) -> ()){
ref.collection("Users").document(uid).getDocument { (doc, err) in
guard let user = doc else{return}
let username = user.data()?["username"] as? String ?? "No Username"
let pic = user.data()?["imageurl"] as? String ?? "No image URL"
let bio = user.data()?["bio"] as? String ?? "No bio"
let uid = doc.document.data()["uid"] as! String ??
DispatchQueue.main.async {
completion(UserModel(username: username, pic: pic, bio: bio, uid: uid))
}
}
}
uj5u.com熱心網友回復:
ifuid是像其他人一樣的欄位username,imageurl然后使用
let uid = user.data()["uid"] as? String ?? ""
如果您已將該 uid 作為檔案的 id,則使用
let uid = doc.documentID
查看檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433705.html
