xcode 线程 1:EXC_BAD_ACCESS(代码=2,地址=0x7ffeeaa26f48)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48936683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeaa26f48)
提问by Claire Cho
I have no clue what this error means
我不知道这个错误是什么意思
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeaa26f48)
which means I have no clue how to fix my code. Please help me. Here is my code below if you need it. If you need more code ask me please. I hope you guys can help me. Edit: I included all of my code. I hope you guys can use it and sorry for not defining the variables that were necessary for this question. Again I hope you guys can solve this.
这意味着我不知道如何修复我的代码。请帮我。如果您需要,这是我的代码。如果您需要更多代码,请询问我。我希望你们能帮助我。编辑:我包含了我的所有代码。我希望你们可以使用它,并且很抱歉没有定义这个问题所必需的变量。再次希望大家能解决这个问题。
var score = 0
var randomAmountOfTime = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime2 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime3 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime4 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime5 = Double(arc4random_uniform(5) + 2)
override func viewDidLoad() {
super.viewDidLoad()
if X != nil {
X.text = ""
}
if Puppy5 != nil {
Puppy5.isHidden = true
}
if Puppy4 != nil {
Puppy4.isHidden = true
}
if Puppy3 != nil {
Puppy3.isHidden = true
}
if Puppy2 != nil {
Puppy2.isHidden = true
}
if Puppy1 != nil {
Puppy1.isHidden = true
}
score = 0
if Score != nil {
Score.text = "Score - \(score)"
}
loadingProcess()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet var Score: UILabel!
@IBOutlet var X: UILabel!
@IBOutlet var Puppy5: UIButton!
@IBAction func puppy5(_ sender: Any) {
Puppy5.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy4: UIButton!
@IBAction func puppy4(_ sender: Any) {
Puppy4.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy3: UIButton!
@IBAction func puppy3(_ sender: Any) {
Puppy3.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy2: UIButton!
@IBAction func puppy2(_ sender: Any) {
Puppy2.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy1: UIButton!
@IBAction func puppy1(_ sender: Any) {
Puppy1.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
func loadingProcess() {
if self.Puppy1 != nil && self.Puppy1.isHidden == true {
let when = DispatchTime.now() + randomAmountOfTime
DispatchQueue.main.asyncAfter(deadline: when) {
self.Puppy1.isHidden = false
self.loadingProcess()
}
} else if self.Puppy1 != nil && self.Puppy1.isHidden == false {
let when = DispatchTime.now() + 3
DispatchQueue.main.asyncAfter(deadline: when) {
self.Puppy1.isHidden = true
if self.X.text == "X" {
self.X.text = "X X"
} else if self.X.text == "" {
self.X.text = "X"
} else if self.X.text == "X X" {
self.X.text = "X X X"
}
}
}
self.loadingProcess()
}
回答by Omar
You're calling self.loadingProcess()
recursively without any condition. This infinite loop is certainly causing the crash.
您在self.loadingProcess()
没有任何条件的情况下递归调用。这个无限循环肯定会导致崩溃。