swiftUI | Missing arguments...

Good day,

I'am learning swiftUI since this week but at this point I'am seriously disappointed. I've been trying to fix this issue since +4hrs, but I don't get it...

Maybe you guys will help me..

Error messages:

▶︎ HomePageView.swift:63:37 Missing argument for parameter 'forUser' in call

▶︎ HomePageView.swift:375:22 Missing argument for parameter 'dataManager' in call

▶︎ LoginPageView.swift:28:38 Missing argument for parameter 'dataManager' in call

▶︎ LoginPageView.swift:131:26 Value of type 'LoginPageView' has no member 'getUserData'

Here you will have Code snippets:

LoginPageView.swift

import SwiftUI
import CoreData
import Firebase

struct LoginPageView: View {
    @State private var email: String = ""
    @State private var password: String = ""
    @State private var isAuthenticated = false
    @State private var showAlert = false
    @State private var errorMessage: String = ""
    @Environment(\.scenePhase) private var scenePhase // Beobachtet den Lebenszyklus der Szene

    @ObservedObject var dataManager = UserDataManager()
    
    var body: some View {
            NavigationView {
                ZStack {
                    Color(hex: "f6f1eb").edgesIgnoringSafeArea(.all)

                    if isAuthenticated {
                        HomePageView()
                    } else {
                        loginForm
                    }
                }
                .navigationTitle(isAuthenticated ? "" : "")
                .navigationBarHidden(isAuthenticated)
                .onChange(of: scenePhase) { newPhase in
                    if newPhase == .background {
                        logout()
                    }
                }
                .onAppear {
                    checkAuthentication()
                }
            }
        }
code-block

HomePageView.swift

struct HomePageView: View {
    @ObservedObject var dataManager: UserDataManager
        
        init(dataManager: UserDataManager) {
            self.dataManager = dataManager
        }
        
    
    var body: some View {
        NavigationView {
            ZStack {
                Color(hex: "f6f1eb")
                    .edgesIgnoringSafeArea(.all)
                VStack {
                    UserProfileView(userRole: dataManager.userRole, userEmail: dataManager.userEmail)
                        .frame(height: 100)
                    Divider()
                    SidebarView()
                }
            }
        }
        .onAppear {
            dataManager.getUserData()
            
        }
        .navigationBarTitle("Split View")
    }
}

struct HomePageView_Previews: PreviewProvider {
    static var previews: some View {
        HomePageView()
    }
}
code-block

DataManager.swift

class UserDataManager: ObservableObject {
    @Published var userRole: String = "Loading..."
    @Published var userEmail: String = "Loading..."
    
    func getUserData(forUser userId: String) {
        let db = Firestore.firestore()
        db.collection("UserRole").document(userId).getDocument { (document, error) in
            if let document = document, document.exists {
                if let data = document.data() {
                    if let role = data["Role"] as? String, let email = data["EMailAddress"] as? String {
                        // Speichern Sie die Benutzerrolle und E-Mail-Adresse in Ihrem UserDataManager
                        self.userRole = role
                        self.userEmail = email
                    }
                }
            } else {
                print("Document does not exist")
            }
        }
    }
}
 
code-block

Thanks in advance for your help and insights. I appreciate your support and look forward to your responses.

Hi Noel, I would like to help you. Unfortunately, the code is incomplete, so I can only assist to a limited extent. Please make sure to use the 'Environment' during observation. I recommend watching the video https://www.youtube.com/watch?v=jD6c9y8CFGQ&t=1793s.

Regarding the first error in 'HomePageView.swift:63:37,' 'Missing argument for parameter 'forUser' in call,' and the function 'getUserData' expects a 'forUser' parameter, which you do not pass when calling it in the 'onAppear' block. I'd be happy to assist you further if you post the entire code here.

Hi Zikomiko,

thank you for your reply. The complete code is a bit too big to post it here completely. But i was able to solve the issues by myself 😁.

swiftUI | Missing arguments...
 
 
Q