快速输入错误的凭据,则显示警报

时间:2020-08-13 23:00:15

标签: swift xcode alamofire alert

输入错误的用户名或密码时,我的应用程序挂起 我想在输入输入错误时显示警报,这是我的尝试

switch response.result {
                case .success:
                    
                    let responseData = response.value as? NSDictionary

//下一行错误为线程1:致命错误:在展开可选值时意外发现nil

                    let successDic: NSDictionary = responseData?.value(forKey: "success") as! NSDictionary 

                    let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "homeVC") as? HomeVC
                    self.navigationController?.pushViewController(vc!, animated: true)
                    break

万一发生故障,程序控制权就不在这里,而是进入成功案例,并显示出我所提到的错误

                    case .failure:
                        self.ShowAlert(title: "Warning", message: "Please enter valid credentials")
                    break
            }

0 个答案:

没有答案