Ios 编译器无法在合理时间内对此表达式进行类型检查-->;Xcode swift
嘿,我刚刚开始使用Xcode,但我对Swift了解不多。我学习了一个关于如何使用SwiftUI在IOS上创建Tic-Tac-Toe应用程序的在线教程。 我的问题如下: 在某些情况下,会出现一个错误,提示我“尝试将表达式分解为不同的子表达式” 下面是我代码中显示的部分:Ios 编译器无法在合理时间内对此表达式进行类型检查-->;Xcode swift,ios,swift,swiftui,Ios,Swift,Swiftui,嘿,我刚刚开始使用Xcode,但我对Swift了解不多。我学习了一个关于如何使用SwiftUI在IOS上创建Tic-Tac-Toe应用程序的在线教程。 我的问题如下: 在某些情况下,会出现一个错误,提示我“尝试将表达式分解为不同的子表达式” 下面是我代码中显示的部分: var body: some View { VStack{ LazyVGrid(columns: Array(repeating:
var body: some View {
VStack{
LazyVGrid(columns: Array(repeating:
GridItem(.flexible(), spacing: 15), count: 3), spacing: 15){
ForEach(0..<9,id: \.self){ index in
ZStack{
if moves [index] == "X"{
Color.orange
}
else {
Color.yellow
}
Color.white
.opacity(moves[index] == "" ? 1 : 0)
Text(moves[index])
.font(.system(size: 50))
.fontWeight(.heavy)
.foregroundColor(.white)
.opacity(moves[index] != "" ? 1 : 0)
}
.frame(width: getWidth(), height: 140)
.cornerRadius(18)
.rotation3DEffect(
.init(degrees: moves[index] != "" ? 180 : 0),
axis: (x: 0.0, y: 1.0, z: 0.0),
anchor: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/,
anchorZ: /*@START_MENU_TOKEN@*/0.0/*@END_MENU_TOKEN@*/,
perspective: 1.3
)
// Whenever tapped adding move...
.onTapGesture(perform: {
withAnimation(Animation.easeIn(duration: 0.5)){
if moves [index] == ""{
moves[index] = isPlaying ? "X" : "0"
isPlaying.toggle()
}}
})
}
}
.padding(15)
}
}
// Whenever moves updated it will check for winner...
.onChange(of: moves, perform: { value in
checkWinner()
})
.alert(isPresented: $gameOver, content:{
Alert(title: ("Winner"), message: Text(msg), dismissButton: .destructive(Text("Play Again"), action: {
//resetting all data...
withAnimation(Animation.easeIn(duration: 0.5)){
moves.removeAll()
moves = Array(repeating: "", count: 9)
isPlaying = true
}
}))
})
}
var主体:一些视图{
VStack{
LazyVGrid(列:数组(重复:
GridItem(.flexible(),间距:15),计数:3),间距:15){
ForEach(0..您的警报
不正确。您传递的是字符串而不是文本。还要检查您的{}对;之前的一对。
不平衡
调试的方法是按照错误指示执行。将视图拆分为较小的视图。Cmd-Shift-A,精确子视图对此非常有用。当视图较小时,编译器更有可能提供良好的错误消息。无论如何,将视图拆分为较小的子视图是一种很好的做法。视图在Swi中非常便宜ftUI和都是相对简单的。错误显示,建议我“尝试将表达式分解为不同的子表达式”-这是一个很好的建议,表明您的视图可能太复杂。即使在某些情况下错误可能会误导,也尝试按照建议操作。至少,大括号不匹配。}
之前的.onChange
与变量主体处的{
匹配。