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.