gpt4 book ai didi

ios - Xcode 7 + swift 。 "Use of local variable ' _' before its declaration"错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:46 25 4
gpt4 key购买 nike

我在尝试创建检查用户输入和存储数据的函数时遇到上述错误。在我到达此函数 RegisterButtonTapped() 之前,我的项目构建良好。有没有人有一些结构或语法更改可以消除此错误?

   @IBAction func RegisterButtonTapped(sender: AnyObject) {

let userEmail = userEmailTextField.text;
let userPassword = userEmailTextField.text;
let userRepeatPassword = userRepeatPasswordTextField.text;


// Check for empty fields
if(userEmail!.isEmpty || userPassword!.isEmpty || userRepeatPassword!.isEmpty){

displayAlertMessage("All fields are required");

return;
}

// Check if passwords match
if(userPassword != userRepeatPassword){

displayAlertMessage("Passwords do not match");

return;
}

// Store Data
NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey: "userEmail");
NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey: "userPassword");
NSUserDefaults.standardUserDefaults().synchronize();

// Display Alert message with confirmation
var myAlert = UIAlertController(title:"Alert",message:"Registration is successful, thank you.",preferredStyle: UIAlertControllerStyle.Alert);

func displayAlertMessage(userMessage:String){

var myAlert = UIAlertController(title:"Alert",message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);

let okAction = UIAlertAction(title:"ok",style: UIAlertActionStyle.Default, handler:nil);

myAlert.addAction(okAction);
self.presentViewController(myAlert, animated: true, completion: nil);
} // END OF FUNCTION 'displayAlertMessage()'



} // END of FUNCTION 'RegisterButtonTapped()'

最佳答案

当你有一个嵌套函数时,你必须在调用它之前声明它。在这种情况下,将“displayAlertMessage(userMessage:String)”函数移到“//Check for empty fields”注释上方,然后它应该可以编译。

关于ios - Xcode 7 + swift 。 "Use of local variable ' _' before its declaration"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38598019/

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