gpt4 book ai didi

ios - ResetPassword 中警报中的可选文本 - 使用 Swift 的 iOS 项目

转载 作者:可可西里 更新时间:2023-11-01 01:37:02 24 4
gpt4 key购买 nike

这是我使用 xcode 和 swift 为我的 iOS 应用程序重置密码按钮:

//ResetPssword Button
@IBAction func ResetPassword(sender: AnyObject) {

if validateEmail(EmailTextField.text!) == false {
print("Enter a Valid Email Address")
let VaildMessage = "Enter an Email Address"
//Empty TextField Alert Message
self.disaplayErrorMessage(VaildMessage)
}

//Reset
else {

ref.resetPasswordForUser(EmailTextField.text) { (ErrorType) -> Void in
if ErrorType != nil {

let error = ErrorType
print("There was an error processing the request \(error.description)")
let errorMessage:String = "The Email You Entered is not Exist"
//Error Alert Message
self.disaplayErrorMessage(errorMessage)

} else {

print("Password Reset Sent Successfully")
let successMessage = "Email Message was Sent to You at \(self.EmailTextField.text)"

//Success Alert Message
self.disaplayErrorMessage(successMessage)
}

} //reset

} //Big Else

} //Button


//Display Alert Message With Confirmation
func disaplayErrorMessage(theMessage:String)
{
//Display alert message with confirmation.
let myAlert = UIAlertController(title: "Alert", message: theMessage, preferredStyle: UIAlertControllerStyle.Alert);

let OkAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) {
action in
self.dismissViewControllerAnimated(true, completion: nil);
}
myAlert.addAction(OkAction);
self.presentViewController(myAlert, animated: true, completion: nil)
}


//Validate Email Function
func validateEmail(candidate: String) -> Bool {
let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
return NSPredicate(format: "SELF MATCHES %@", emailRegex).evaluateWithObject(candidate)
}

如果密码重设发送成功,将会有一条打印出电子邮件地址的警报。但是它会打印带有可选单词的电子邮件!

enter image description here

如果没有可选字,如何打印?

最佳答案

您必须展开可选文本字段。

例如if let:

if let text = self.EmailTextField.text {
let successMessage = "Email Message was Sent to You at \(text)"
//Success Alert Message
self.disaplayErrorMessage(successMessage)
}

关于ios - ResetPassword 中警报中的可选文本 - 使用 Swift 的 iOS 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com