Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios “显示”的问题;线程1:EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0)";运行时_Ios_Swift_Xcode_Swiftui - Fatal编程技术网

Ios “显示”的问题;线程1:EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0)";运行时

Ios “显示”的问题;线程1:EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0)";运行时,ios,swift,xcode,swiftui,Ios,Swift,Xcode,Swiftui,在运行期间,应用程序将重置为白色屏幕,并在SceneDelegate.swift下显示“Thread 1:EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0”。可能是什么问题?如果我在编写代码的过程中学习,因此遗漏了文章中的任何内容,请道歉。谢谢 import SwiftUI struct ContentView: View { @State private var countries = ["Estonia", "France", "Ger

在运行期间,应用程序将重置为白色屏幕,并在SceneDelegate.swift下显示“Thread 1:EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0”。可能是什么问题?如果我在编写代码的过程中学习,因此遗漏了文章中的任何内容,请道歉。谢谢

import SwiftUI

struct ContentView: View {
@State private var countries = ["Estonia", "France", "Germany", "Ireland", "Italy", "Nigeria", "Poland", "Russia", "Spain", "UK", "US"].shuffled()
@State private var correctAnswer = Int.random(in: 0...2)

@State private var showingScore = false
@State private var scoreTitle = ""

var body: some View {

    ZStack {
        Color.blue.edgesIgnoringSafeArea(.all)
        VStack(spacing: 30) {
            VStack {
                Text("Tap the flag of")
                foregroundColor(.white)

                Text(countries[correctAnswer])
                foregroundColor(.white)
            }

            ForEach(0 ..< 3) { number in
                Button(action: {
                   self.flagTapped(number)
                }) {
                    Image(self.countries[number])
                        .renderingMode(.original)
                    }
                }
            }
        }
    .alert(isPresented: $showingScore) {
        Alert(title: Text(scoreTitle), message: Text("Your score is     ???"), dismissButton: .default(Text("Continue")) {
                self.askQuestion()
            })
        }
    }
func flagTapped(_ number: Int) {
    if number == correctAnswer {
        scoreTitle = "Correct"
    } else {
        scoreTitle = "Wrong"
    }

    showingScore = true
}

func askQuestion() {
    countries.shuffle()
    correctAnswer = Int.random(in: 0...2)
}
导入快捷界面
结构ContentView:View{
@国家/私营var国家=[“爱沙尼亚”、“法国”、“德国”、“爱尔兰”、“意大利”、“尼日利亚”、“波兰”、“俄罗斯”、“西班牙”、“英国”、“美国”]。shuffled()
@国家私有变量correctAnswer=Int.random(in:0…2)
@状态私有变量showingScore=false
@国家私有var scoreTitle=“”
var body:一些观点{
ZStack{
颜色.蓝色.边缘识别安全区域(.all)
VStack(间距:30){
VStack{
文本(“点击的标志”)
前底色(.白色)
文本(国家[答复])
前底色(.白色)
}
ForEach(0..<3){
按钮(操作:{
自动标记(编号)
}) {
图像(self.countries[编号])
.renderingMode(.original)
}
}
}
}
.警报(显示:$showingScore){
警报(标题:文本(scoreTitle),消息:文本(“您的分数是?”),解除按钮:。默认值(文本(“继续”)){
self.askQuestion()
})
}
}
func flagstapped(uu编号:Int){
如果数字==正确答案{
scoreTitle=“正确”
}否则{
scoreTitle=“错误”
}
showingScore=true
}
func askQuestion(){
国家。洗牌()
correctAnswer=Int.random(in:0…2)
}

这是一个非常有趣的意外巧合问题,但这里有一个解决方案

Text("Tap the flag of")
   .foregroundColor(.white)   // << use '.' (dot) before foregroundColor!!

Text(countries[correctAnswer])
   .foregroundColor(.white)   // << same !!
Text(“点击的标志”)

.foregroundColor(.white)/这是一个非常有趣的意外巧合问题,但这里有一个解决方案

Text("Tap the flag of")
   .foregroundColor(.white)   // << use '.' (dot) before foregroundColor!!

Text(countries[correctAnswer])
   .foregroundColor(.white)   // << same !!
Text(“点击的标志”)
.foregroundColor(.白色)//