【发布时间】:2022-01-08 22:25:22
【问题描述】:
我是 SwiftUI 和 Xcode 13.2 的新用户。我正在学习关于 Udemy 的课程,但是当出现“无法为表达式生成诊断;请提交错误报告 (https://swift.org/contributing/#reporting-bugs) 并包含该项目”的错误时遇到了障碍。上面写着var body: some View {}。这是完整的代码。
import SwiftUI
struct ContentView: View {
@State var userText:String = ""
@State var mode:Int = 1
var body: some View {
VStack {
if mode == 1 {
Text(userText.capitalized())
.font(.largeTitle)
} else if mode == 2 {
Text(userText.lowercased())
.font(.largeTitle)
} else {
Text(userText.uppercased())
.font(.largeTitle)
}
}
TextField("Enter text here...", text: $userText)
.background(Color.yellow)
.padding()
Text(userText)
.font(.largeTitle)
HStack{
Button(action: {mode = 1}) {
RoundedButton(text: "Capitalize", color: .green)
.padding(5)
}
Button(action: {mode = 2}) {
RoundedButton(text: "Lower", color: .blue)
}
Button(action: {mode = 3}) {
RoundedButton(text: "All Caps", color: .red)
.padding(5)
}
}
}
}
struct RoundedButton: View {
var text:String
var color:Color
var body: some View {
Text(text)
.bold()
.frame(maxWidth:.infinity)
.padding()
.background(color)
.foregroundColor(.black)
.cornerRadius(10)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewInterfaceOrientation(.portrait)
}
}
我该如何解决这个问题?
【问题讨论】:
-
逐行注释掉,一般是拼写错误。
标签: swift xcode error-handling swiftui xcode13