HomeiOS Developmentios - Easy methods to fetch consumer knowledge

ios – Easy methods to fetch consumer knowledge


I’m attempting to learn to cross consumer knowledge with swiftui I’ve tried utilizing the UserDataFile to fetch the consumer knowledge from firebase firestore to look on my consumer profile however I’m not receiving nothing on the interface That is my knowledge mannequin

class UserDataFile: ObservableObject {
    func FetchUser() {
        let consumer = Auth.auth().currentUser
        if let consumer = consumer {
            let db = Firestore.firestore()
            let docRef = db.assortment("consumer").doc("ProfileImages")
            docRef.getDocument { (doc, error) in
                 if let doc = doc, doc.exists {
                     let dataDescription = doc.knowledge().map(String.init(describing:)) ?? "nil"
                     print("Doc knowledge: (dataDescription)")
                 } else {
                     print("Doc doesn't exist")
                 }

Once I run the app I obtained this error

Deadly error: No ObservableObject of sort UserDataFile discovered. A View.environmentObject(_:) for UserDataFile could also be lacking as an ancestor of this view.

That is my consumer profile display code I’m utilizing @EnvironmentObject to fetch my consumer knowledge from firebase in order that my consumer info seem mechanically on the consumer profile display

What am I lacking from this code and the way do I correctly fetch consumer knowledge ?

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments