gpt4 book ai didi

swift - 线程 1 : signal SIGSTOP runtime error

转载 作者:搜寻专家 更新时间:2023-11-01 07:30:27 25 4
gpt4 key购买 nike

我对 Swift 很陌生,所以我不太确定错误发生在哪里。

这是我的 View Controller 。也许我没有正确调用函数,因为在我包含更改时态的函数后开始发生此错误。

有趣的是,如果我重新启动运行 iOS 9 的模拟器并且没有给我任何运行时错误,应用程序运行良好。我使用的是 Xcode 7.0 beta 版。

任何帮助将不胜感激。

提前致谢。

import UIKit
import AVFoundation


class ViewController: UIViewController {


let synth = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance(string: "")

var sentence = ""

let subject: [String] = ["I", "You", "He" , "She", "We", "They"]




let verbNoun = [["eat" ,"eats", "ate", "will eat", "an apple", "a banana", "a cake", "a sandwhich" ],
["drink" ,"drinks", "drank", "will drink", "water", "milk","tea","coffee"]]



var i = 0
var j = 0
var t = 0
var k = 4
var subjectCount = 6 //var subjectCount = subject.count()
var verbCount = 2
var nounCount = 4
var tense = "present"


func modulo (a: Int, b: Int) ->Int{

if a%b<0 {

return ((a%b)+b)


}else{

return a%b

}

}

func getTense(tense: String) ->Int{


if tense == "present" {
return 0
if i==2 || i==3 { return 1}
}
else if tense == "past" { return 2 }
else if tense == "future" { return 3 }

return 0
}



/* func sentenceGenerator(s: String, v: String, n: String) -> Void {

verbLabel!.text = v

nounLabel!.text = n

subjectLabel.text = s


}
*/


@IBOutlet var subjectLabel: UILabel!

@IBOutlet var verbLabel: UILabel!

@IBOutlet var nounLabel: UILabel!

@IBOutlet var sent: UILabel!


@IBAction func futureTense(sender: AnyObject) {

tense = "future"

t = getTense(tense)

verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]
subjectLabel!.text = subject[i]

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]


sent!.text = sentence

}





@IBAction func pastTense(sender: AnyObject) {



tense = "past"



t = getTense(tense)

verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]
subjectLabel!.text = subject[i]

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]


sent!.text = sentence

}





@IBAction func subjectPrevious(sender: AnyObject) {

i--

i = modulo(i,b: subjectCount)

t = getTense(tense)

subjectLabel!.text = subject[i]
verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]


// sentenceGenerator(subject[i], v: verbNoun[j][t], n: verbNoun[j][k])

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]


sent!.text = sentence

}




@IBAction func subjectNext(sender: AnyObject) {


i++

i = modulo(i,b: 6)

t = getTense(tense)

subjectLabel!.text = subject[i]
verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]

sent!.text = sentence

}




@IBAction func verbNext(sender: AnyObject) {


j++

j = modulo(j,b: verbCount)

t = getTense(tense)


verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]

sent!.text = sentence

}


@IBAction func verbPrevious(sender: AnyObject) {

j--

j = modulo(j,b: verbCount)

t = getTense(tense)


verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]


sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]


sent!.text = sentence

}




@IBAction func nounPrev(sender: AnyObject) {

k--

k = modulo(k,b: nounCount)+4

t = getTense(tense)

verbLabel!.text = verbNoun[j][t]

nounLabel!.text = verbNoun[j][k]

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]

sent!.text = sentence

}


@IBAction func nounNext(sender: AnyObject) {

k++

k = modulo(k,b: nounCount)+4

t = getTense(tense)

verbLabel!.text = verbNoun[j][t]
nounLabel!.text = verbNoun[j][k]

sentence = subject[i] + " " + verbNoun[j][t] + " " + verbNoun[j][k]

sent!.text = sentence
}


@IBAction func splish(sender: AnyObject) {

myUtterance = AVSpeechUtterance(string: sentence)
myUtterance.rate = 0.4
synth.speakUtterance(myUtterance)


}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.=


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/* override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}

func textFieldshouldReturn(textField: UITextField) -> Bool{

textField.resignFirstResponder()

return true
}*/
}

最佳答案

这是一个很好的问题示例,因为您不够具体,所以不会得到好的答案。对于像您这样正在学习的人,这里有一些关于调试和获得良好帮助的提示。

1) 准确告诉大家问题出在哪里。听起来您的应用程序正在以 SIGSTOP 终止,然后堆栈跟踪不会告诉您它发生的位置。但我不确定这是真的,因为你只是把错误放在标题中。在正文中清楚地陈述你知道的一切。

2) 并且不要包含您不知道相关的代码,只包含发生崩溃或直接相关的代码。人们总是可以要求您提供更多代码,但代码越多,就越难理解您在做什么。

3) 如果您不知道崩溃发生在何处,请在调试器中设置断点并跟踪直到发生错误,然后将行告诉我们。在这种情况下,我将从您添加的新代码开始。通常,如果您知道该行,您会自己发现问题,从而节省您编写此内容的时间。

4) 如果设置断点并单步执行代码无法将您带到崩溃发生的地方,请进入调试器断点,单击其 View 左下角的 + 按钮(它应该是使用调试器运行时屏幕左侧)并添加“异常断点”。 Swift 无法捕获来自 Objective C 代码/库/框架的异常,此断点将为您捕获它们并为您提供有关它们发生位置的更多信息。

如果您努力准确地确定错误发生的位置,通常很容易自行修复错误。我知道这对你有帮助已经很晚了,但希望这对其他新 Swifties 有帮助,

最美好的祝愿,兰迪

关于swift - 线程 1 : signal SIGSTOP runtime error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32765436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com