gpt4 book ai didi

swift - 无法调用 "isValidEmail",参数错误

转载 作者:行者123 更新时间:2023-11-30 10:15:18 25 4
gpt4 key购买 nike

我是 swift 新手,面临验证电子邮件的小问题

//Login API CALL
@IBAction func loginButton(sender: AnyObject) {
var userModel = UserModel();
var data_info: [String:AnyObject] =
[
"udid" : "",
"email" : "someemail",
"password" : "soempass"
];
var checkInput = UserModel.isValidEmail(data_info["email"]); //Error here
if (checkInput) {
var isTrue = UserModel.doLogin(data_info:Dictionary<String,AnyObject>.self);
}
}

//Validate Email
func isValidEmail(testStr:AnyObject) -> Bool {
println("validate emilId: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
var emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
var result = emailTest.evaluateWithObject(testStr)
return result
}

有什么类型问题吗?我应该将 AnyObject 更改为 String 吗?UserModel 是一个验证电子邮件地址的外部类谢谢提前!

最佳答案

尝试使用小写的“u”,这就是实例,使用大写的“U”它是类

userModel.isValidEmail(data_info["email"]);

关于swift - 无法调用 "isValidEmail",参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30433895/

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