swift - Swift:无法将任何视图的返回表达式转换为某个视图的返回类型
问题描述
我不知道我有什么错误:无法将任何视图的返回表达式转换为返回类型某个视图
我尝试了一些东西,但没有任何效果......我在网上一无所获
谢谢你的帮助...
struct LoginView: View {
@Binding var showCreateAccount: Bool
@State private var email = ""
@State private var password = ""
@State private var formOffset: CGFloat = 0
@State private var presentPasswordRecoverySheet = false
var body: some View {
VStack {
VStack(spacing: 40) {
Image("Logo")
Text("Login").font(.title).bold()
VStack {
RoundTextfield(value: self.$email, placeholder: "Email", icon: Image(systemName: "at"),
onEditingChanged: { flag in withAnimation { self.formOffset = flag ? -150 : 0 } })
RoundTextfield(value: self.$password, placeholder: "Password", icon: Image(systemName: "lock"), isSecure: true,
onEditingChanged: { flag in withAnimation { self.formOffset = flag ? -150 : 0 } })
BasicButton(text: "Login") {}
}
Button(action: { withAnimation(.spring() ) { self.showCreateAccount.toggle() } } )
{
HStack { Text("Don't have an account? Sign up.").accentColor(Color.accentColor) }
}
Button(action: { self.presentPasswordRecoverySheet.toggle() } )
{
HStack { Text("Forgot your password?").accentColor(Color.purple) }
}
.sheet(isPresented: self.$presentPasswordRecoverySheet)
{ RecoverPasswordView(presentPasswordRecoverySheet: self.$presentPasswordRecoverySheet) }
}
.padding()
.offset(y: self.formOffset)
}
}
这是我的 BasicButton 代码,但我认为这不是问题
struct BasicButton: View {
var text = "Next"
var action: (()->()) = {}
var body: some View {
Button(action: {
self.action()
}) {
HStack {
Text(text)
.bold()
.frame(minWidth: 0, maxWidth: .infinity)
.padding(.vertical)
.accentColor(Color.white)
.background(Color("accentColor"))
.cornerRadius(30)
}
}
}
}
struct BasicButton_Previews: PreviewProvider {
static var previews: some View {
BasicButton()
}
当我删除创建帐户和忘记密码的两个按钮功能时,代码可以构建
解决方案
I’ve been fiddling with the same error all day. There’s no issues when building/running normally. It's very strange. I even tried commenting out almost all of the code in my view except for one small piece of it and I’m still hitting a problem with .font(.title)
. Amazingly, if I try running the same code in a new project, no problem. Also if I just comment out that line setting the font type the preview compiles and shows up.
And the errors being reported are basically non-sense, they’re not even on the right line.
So I guess the preview feature is just riddled with bugs still. Hopefully it improves soon. Feels like the initial rollout of Swift where people started adopting and using it faster than Apple was able to fix it. Or rather, Swift was probably released before the tooling was ready for it. Seems to be the same case here with SwiftUI.
推荐阅读
- android - 为自定义首选项膨胀类时出错
- excel - Excel 数组公式中的当前行占位符
- r - 当我从 R 中的 ncdf 文件中提取值时发生错误
- excel - Function.Invoke 麻烦后
- c# - 如何插入一个 void 函数作为另一个方法的参数
- android - onItemClick 不适用于适配器(线性布局)
- git - Bitbucket 服务器和 Teamcity - 如何使用目标分支自动更新功能分支
- cpanel - 更改为第三方邮件服务器
- jsp - Kendo UI Combobox 示例代码在 jsp 中不起作用
- vb.net - 是否可以在 My.Computer.Audio.Play VB.NET 上有超过 3 个重载