I am trying to get data back from the Firebase Firestore but have come in to one or maybe more problems
Here is my code
I a trying to get a specific document with the id of the current user id
import SwiftUI
import Firebase
import FirebaseFirestore
import FirebaseFirestoreSwift
class UsersModel: ObservableObject {
@Published var userData = [UserData]()
let userID = Auth.auth().currentUser!.uid
private var db = Firestore.firestore()
func fetchData() {
db.collection("users").document(userID).addSnapshotListener { (querySnapshot, error) in
guard let document = QuerySnapshot?.documents() else {
print("No documents")
return
}
self.userData = document.compactMap{(QueryDocumentSnapshot) -> UserData? in
return try? QueryDocumentSnapshot.data(as: UserData.self)
}
}
}
}
but on this line guard let document = QuerySnapshot?.documents() else {
I get this error Type 'QuerySnapshot?' has no member 'documents'
I am using the Coddle protocol
Here is my UserData
import SwiftUI
import FirebaseFirestoreSwift
struct UserData: Identifiable, Codable {
@DocumentID var id: String?
var username: String
var ImageURl: URL
}
What am I doing wrong and how can I fix this please
Many Thanks for your help