class SignModelView: ObservableObject {
let auth = Auth.auth()
@Revealed var signedIn = false
@Revealed var present = false
@Revealed var show2 = false
@Revealed var successalert = AlertToast(sort: .full(.inexperienced), title: "Account Created!"){
didSet{
present.toggle()
}
}
@Revealed var resetalert = AlertToast(sort: .full(.inexperienced), title: "E-mail Despatched"){
didSet{
show2.toggle()
}
}
var isSignedIn: Bool {
return auth.currentUser != nil
}
func SignIn(electronic mail: String, password: String) {
auth.signIn(withEmail: electronic mail, password: password) {[weak self] outcome, error in
guard outcome != nil, error != nil else { return }
if let errCode = AuthErrorCode(rawValue: error!._code) {
change errCode {
case .wrongPassword:
debugPrint("improper electronic mail or password")
case .invalidEmail:
debugPrint("improper electronic mail or password")
case .tooManyRequests:
debugPrint("login after someday")
default:
DispatchQueue.most important.async { [weak self] in
self?.signedIn = true
}
}}
}
}
func SignUp(withEmail electronic mail: String, password: String) {
auth.createUser(withEmail: electronic mail, password: password) {outcome, error in
guard outcome != nil, error != nil else { return }
if let errCode = AuthErrorCode(rawValue: error!._code) {
change errCode {
case .emailAlreadyInUse:
print("already exists")
case .credentialAlreadyInUse:
print("already exists")
default:
print("Signed Up")
}
}
}
}
func signOut() {
attempt? auth.signOut()
self.signedIn = false
}
}
NavigationLink("", vacation spot: MasterView(), isActive: $isMastertapped)
VerifyBoxView(checked: $checked, trimVal: $trimVal, width: $width, removeText: $removeText)
.disabled(electronic mail.isEmpty || password.isEmpty)
.onTapGesture {
isMastertapped.toggle()
guard !electronic mail.isEmpty, !password.isEmpty else {
return
}
viewModel.SignIn(electronic mail: electronic mail, password: password)
debugPrint("Signed In")
if !self.checked {
self.removeText.toggle()
withAnimation {
self.width = 100
}
withAnimation(Animation.easeIn(length: 0.7)) {
self.trimVal = 2
self.checked.toggle()
}
} else {
withAnimation {
self.trimVal = 0
self.width = 125
self.removeText.toggle()
self.checked.toggle()
}
}
}
.disabled(electronic mail.isEmpty || password.isEmpty)
My navigationlink takes me to the subsequent view, nonetheless in MasterView(), I’m downloading the present person’s electronic mail ID which supplies me a 0 error everytime until I give a default worth. DispatchQueue doesn’t appear to work with the navigation hyperlink
var userMail : String = Auth.auth().currentUser?.electronic mail ?? "lol@lol.com"
That is the code within the subsequent view.
How do I repair this to forestall a crash and have the info downloaded earlier than I get to the subsequent view?