2023-03-30

How to fetch user data?

firestore contents I am trying to fetch my user data from firestore I set up a model class that’s an observable object to fetch the document data from Firestore to appear on the user interface but I been receiving this error. How do I fix this code to get user data from Firebase ?

Cannot convert value of type 'String' to expected argument type 'URL'

class NewUserData: ObservableObject {
    
    @Published var datas = [UserModelFile]()
    
   
    
    func fetchUser() {
        let db = Firestore.firestore()
      let ref = db.collection("user")
            
        ref.getDocuments { snapshot, error in
            guard error == nil else {
                print(error!.localizedDescription)
                return
            }
        
            if let snapshot = snapshot {
                for document in snapshot.documents {
                    let data = document.data()
                    
                    let username = data["username"] as? String ?? ""
                    let bio = data["bio"] as? String ?? ""
                    let profileImages = data["bio"] as? String ?? ""
                    
                    let data = UserModelFile(username: username, bio: bio
                                             , ProfileImages: profileImages)
                    self.datas.append(data)
                }
 


No comments:

Post a Comment