类型 '()' 不能符合 SWIFT 上的 "View"



当我尝试验证SecureTextField字段下的密码字段时,会出现此错误。

有什么想法吗?我对用于电子邮件验证的TextField做了类似的操作,效果很好!我的问题是密码验证";如果";

HStack {

TextField("Email Address", text: $loginVM.credentials.email) { isEditing in
self.isEditing = isEditing

errorMessage = ""
////// == getting  email validation boolean after losing  the focus
if  isEditing  == false  {
if validateEmail(emailAddressString: loginVM.credentials.email) ==  true {
errorMessage = "YES, Email is Good"
print(errorMessage)
} else {
errorMessage = "*-Oops,Something is wrong with your email !!!"
print(errorMessage)
}
}

}

} .textFieldStyle(MyTextFieldStyle(focused: $isEditing))


HStack {

SecureTextField(text: $loginVM.credentials.password)
.padding(10)
.focused($isInFocus)
.background(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(isInFocus ? Color.orange : Color.gray, lineWidth: 1))


}.disableAutocorrection(true)
// Here is where I'm getting this Type '()' cannot conform to 'View'
if validatePassword(passwordString: loginVM.credentials.password) ==  true {
errorMessage = "YES, Password  OK"
print(errorMessage)
} else {
errorMessage = "*-Oops,Something is wrong with your Password !!!"
print(errorMessage)
}

您可以将逻辑封装在onSubmit中。

编译器希望ViewBuilder 中包含一些视图

SecureTextField(text: $name)
.padding(10)
.focused($isInFocus)
.disableAutocorrection(true)
.background(
RoundedRectangle(
cornerRadius: 10,
style: .continuous
)
.stroke(isInFocus ? Color.orange : Color.gray, lineWidth: 1)
)
.onSubmit {
if validatePassword(passwordString: loginVM.credentials.password) {
errorMessage = "YES, Password  OK"
print(errorMessage)
} else {
errorMessage = "*-Oops,Something is wrong with your Password !!!"
print(errorMessage)
}
}

当用户按下键盘上的提交按钮时,.onSubmit块将执行,尽管我建议在视图模型中处理该逻辑,并在设置完后执行该逻辑

相关内容

  • 没有找到相关文章