Post

Replies

Boosts

Views

Activity

Firebase Authentication error handling
I want to display the error message to the user if there is an error with signing in. I created a state var called loginStatusMessage and added it in the signUp function and passed it to the view where i want to display the message but it is not showing up in the view. AppViewModel @State var loginStatusMessage = ""  `func signUp(email: String, password: String) {     auth.createUser(withEmail: email, password: password) { [weak self] result, error in       if let error = error {         print("Failed to create user:", error)         self?.loginStatusMessage = "Failed to create user: \(error)"         return       }               print("Successfully created user: \(result?.user.uid ?? "")")               self?.loginStatusMessage = "Successfully created user: \(result?.user.uid ?? "")"               // Success       DispatchQueue.main.async {         self?.signedIn = true       }     }   }` CreateAccountView  Button {             guard !email.isEmpty, !password.isEmpty else {               return             }             viewModel.signUp(email: email, password: password)           } label: {               Text("Create Account")             }           .frame(height: 40)           .foregroundColor(.white)           .background(Color(hue: 0.454, saturation: 0.991, brightness: 0.52, opacity: 0.911))           .buttonStyle(.bordered)           .cornerRadius(5)           .padding(.vertical)                       Text(self.viewModel.loginStatusMessage)             .foregroundColor(.red)
0
0
448
Jan ’23
Thread 1: Fatal error: Index out of range
I am trying to show items in my array quizData[i]. And it is giving me the error Thread 1: Fatal error: Index out of range.  static var currentIndex = 0   static var currentIndex2 = 0       static func createGameModel(i: Int, j: Int) -> Quiz {     return Quiz(currentQuestionIndex: i, quizModel: quizData[i], quizModel2: quizData2[j], quizCompleted: false)   }   @Published var model = GameManagerVM.createGameModel(i: GameManagerVM.currentIndex, j: GameManagerVM.currentIndex2) I tried to change my if statement to GameManagerVM.quizData.count and it s still giving me the error.  DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {           if (GameManagerVM.currentIndex < GameManagerVM.quizData.count) {             GameManagerVM.currentIndex = GameManagerVM.currentIndex + 1             self.model = GameManagerVM.createGameModel(i: GameManagerVM.currentIndex, j: GameManagerVM.currentIndex2)           } else {             self.model.quizCompleted = true             self.model.quizWinningStatus = true             self.reset()
2
0
269
Dec ’22
Cloudkit request permission not working
I am trying to request the users permission to share their information using this function: func requestPermission() {     CKContainer.default().requestApplicationPermission([.userDiscoverability]) { [weak self] returnedStatus,       returnedError in       DispatchQueue.main.async {         if returnedStatus == .granted {         self?.permissionStatus = true         }       }     }   } But it is not working. I am signed into my apple id and it still is not working. Any ideas?
2
0
481
Aug ’22