[英]Type '()' cannot conform to 'View' on SWIFT
I'm getting this error when I try to validate password field under a SecureTextField field.当我尝试验证 SecureTextField 字段下的密码字段时出现此错误。
any thoughts?有什么想法吗? I did similar with an TextField for Email validation and works just fine!我对用于 Email 验证的 TextField 进行了类似的操作,并且工作正常! my issue is with the password validation "If"我的问题是密码验证“如果”
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)
}
you can wrap your logic inside onSubmit
.您可以将逻辑包装在onSubmit
中。
the compiler expects some View inside the ViewBuilder编译器期望 ViewBuilder 中有一些 View
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)
}
}
the .onSubmit
block will execute when the user presses submit button on the keyboard though i would recommend handling this logic inside a view model and execute the logic once everything is set up .onSubmit
块将在用户按下键盘上的提交按钮时执行,但我建议在视图 model 中处理此逻辑并在一切设置好后执行逻辑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.