Post

Replies

Boosts

Views

Activity

Need some help! Failed to produce diagnostic for expression error
Hey y'all, im semi new to the coding world and have just come across this error: Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) ive been building for a little while and can't figure out why. Ive rebuilt and tried everything. Any help would be appreciated! This is the code: import SwiftUI import Combine struct LoginView: View { @EnvironmentObject var authManager: AuthenticationManager @State private var email = "" @State private var password = "" @State private var showingAlert = false @State private var alertMessage = "" @State private var keyboardHeight: CGFloat = 0 var body: some View { GeometryReader { geometry in NavigationView { ZStack { LinearGradient(gradient: Gradient(colors: [Color.red, Color.black]), startPoint: .top, endPoint: .bottom) .edgesIgnoringSafeArea(.all) VStack { Image("GottaDraftEmAll") .resizable() .scaledToFit() .frame(width: geometry.size.width * 0.8, height: geometry.size.height * 0.1) .padding(.top, 25) Spacer() Image("pokeball") .resizable() .scaledToFit() .frame(width: geometry.size.width * 0.6, height: geometry.size.width * 0.6) .padding(.bottom, 20) VStack(spacing: 15) { TextField("", text: $email) .padding() .background(Color.white.opacity(0.8)) .cornerRadius(10) .padding(.horizontal, 20) .foregroundColor(.black) .overlay( HStack { Text(email.isEmpty ? "Email" : "") .foregroundColor(Color.black.opacity(0.7)) .padding(.leading, 25) Spacer() } ) SecureField("", text: $password) .padding() .background(Color.white.opacity(0.8)) .cornerRadius(10) .padding(.horizontal, 20) .foregroundColor(.black) .overlay( HStack { Text(password.isEmpty ? "Password" : "") .foregroundColor(Color.black.opacity(0.7)) .padding(.leading, 25) Spacer() } ) } .padding(.top, 50) Button(action: { authManager.signIn(email: email, password: password) { success, error in if !success { alertMessage = error ?? "An unknown error occurred" showingAlert = true } } }) { Text("LOGIN") .font(.headline) .foregroundColor(.white) .padding() .frame(maxWidth: .infinity) } .buttonStyle(GlowGradientButtonStyle()) .padding(.horizontal, 20) .padding(.top, 20) NavigationLink(destination: SignUpView()) { Text("Don't have an account? Sign Up") .foregroundColor(.white) } .padding(.top, 10) Spacer() } .padding(.bottom, keyboardHeight) } .onAppear { NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { notification in if let value = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect { self.keyboardHeight = value.height } } NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { _ in self.keyboardHeight = 0 } } .onDisappear { NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) } .alert(isPresented: $showingAlert) { Alert(title: Text("Login Error"), message: Text(alertMessage), dismissButton: .default(Text("OK"))) } } } } }
Topic: UI Frameworks SubTopic: SwiftUI
1
0
387
Jul ’24