ios - name textfield made mandatory then UIAlert stopped working -


i added line of code name text-field mandatory when registering account firebase when did uialert broke. stopped showing when added line of code. code added highlighted >. best way fix problem? either recode mandatory name text-field or recode uialert. simplest way?

        @ibaction func registertapped(_ sender: any) {         let namec = nametextfield.text          if let email = emailtextfield.text, let pass = passwordtextfield.text, let name = (namec?.capitalized.isempty)! ? nil:namec?.capitalized {             firauth.auth()?.createuser(withemail: email, password: pass, completion: { (user, error) in                 if user != nil {                     //user found                      let interval = nsdate().timeintervalsince1970                     let date = date(timeintervalsince1970: interval)                     let dateformatter = dateformatter()                     dateformatter.dateformat = "dd/mm/yyyy/hh/mm/ss"                     // can change date format whatever wants                     let datestring = dateformatter.string(from: date)                     print(datestring)                     self.refd?.child("users").child((user?.uid)!).setvalue(["email": email, "name": name, "user created": datestring])                     print("user created , added database", email, name, datestring)                     self.performsegue(withidentifier: "registertologin", sender: self)                 }                 else {                     print(error!)                     let alert = uialertcontroller(title: "error creating account ", message: "\(error!.localizeddescription)", preferredstyle: uialertcontrollerstyle.alert)                     alert.addaction(uialertaction(title: "dismiss", style: uialertactionstyle.default, handler: nil))                     self.present(alert, animated: true, completion: nil)                 }             })         }     } } 

i think have add alert code in main queue block because code inside completion handler block

dispatchqueue.main.async {     print(error!)     let alert = uialertcontroller(title: "error creating account ", message: "\(error!.localizeddescription)", preferredstyle: uialertcontrollerstyle.alert)     alert.addaction(uialertaction(title: "dismiss", style: uialertactionstyle.default, handler: nil))     self.present(alert, animated: true, completion: nil) } 

try this!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -