线程1:发出SIGSTOP运行时错误信号

时间:2015-09-24 15:35:34

标签: swift ios9 xcode7

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

这是我的Viewcontroller。也许我没有正确地调用函数,因为在我包含了更改时态的函数之后,这个错误就开始发生了。

有趣的是,应用程序运行正常,如果我重新启动运行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 个答案:

答案 0 :(得分:2)

这是一个很好的例子,这个问题不会得到很好的答案,因为你还不够具体。对于像你这样正在学习的人,有一些关于调试和获得良好帮助的技巧。

1)告诉每个人确切的问题发生在哪里。听起来你的应用程序被SIGSTOP终止,然后堆栈跟踪不会告诉你它发生在哪里。但我不确定这是真的,因为你只把错误放在标题中。陈述你身体中清楚知道的一切。

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

3)如果您不知道发生崩溃的位置,请在调试器中设置断点并跟踪直到发生错误,并给我们一行。在这种情况下,我将从您添加的新代码开始。通常,如果您知道该行,您将自己找到问题所在,节省您编写本文的时间。

4)如果设置断点并单步执行代码并不能让您到达发生崩溃的位置,请进入调试器断点,单击其左下角的+按钮(它应该是当你使用调试器运行时,它是屏幕左侧的高大区域)并添加一个&#34; Exception Breakpoint&#34;。 Swift无法从Objective C代码/库/框架中捕获异常,并且此断点将为您捕获它们并为您提供有关它们发生位置的更多信息。

如果您确切地确定错误发生的位置,通常可以轻松地自行修复它们。我知道这对你来说已经很晚了,但希望这有助于其他新的Swifties,

最好的祝福, 好色