HomeiOS Developmentios - The right way to fetch a consumer knowledge from firebase

ios – The right way to fetch a consumer knowledge from firebase


I’ve arrange a mannequin class that’s an observable object to fetch the doc knowledge from Firestore however I been receiving this error

Can not convert worth of sort ‘String’ to anticipated argument sort ‘URL’
my picture in firestore is saved as a string

Additionally in my codable DocumentReference is giving me a error in my mannequin

Worth of sort ‘DocumentReference’ has no member ‘getDocuments’

How do I arrange this code to get consumer knowledge from Firebase ?

class NewUserData: ObservableObject {
    
    @Printed var datas = [UserModelFile]()
    
   
    
    func fetchUser() {
        let db = Firestore.firestore()
      let ref = db.assortment("consumer").doc("ProfileImages")
            
        ref.getDocuments { snapshot, error in
            guard error == nil else {
                print(error!.localizedDescription)
                return
            }
        
            if let snapshot = snapshot {
                for doc in snapshot.paperwork {
                    let knowledge = doc.knowledge()
                    
                    let username = knowledge["username"] as? String ?? ""
                    let bio = knowledge["bio"] as? String ?? ""
                    let profileImages = knowledge["bio"] as? String ?? ""
                    
                    let knowledge = UserModelFile(username: username, bio: bio
                                             , ProfileImages: profileImages)
                    self.datas.append(knowledge)
                }
 
struct UserModelFile: Codable,  Identifiable {
    var id: String?{
        ref?.documentID
    }
    @DocumentID var ref: DocumentReference?
    var bio: String
    var username: String
    var profilePic: URL
    
    
}

    struct ProfileHeader: View {
        
        @StateObject var userDataHere = UserDataFile()
        
       
        
        var physique: some View {
              Button {
                            }label: {
                                NavigationLink(vacation spot: AccountView()) {
                                    Textual content("Account")
                                    
                                    
                                        .foregroundColor(.white)
                                        .environmentObject(userDataHere)
                                        .onAppear {userDataHere.fetchUser()}
                                       
                                }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments