2

I am quite new to Swift, so I am not really sure where the error is happening.

This is my Viewcontroller. Maybe I am not calling the functions correctly, as this error started happening after I had included the functions to change the tenses.

The funny thing is, the app runs fine, if I reboot the simulator which is running iOS 9 and does not give me any runtime error. I am using Xcode 7.0 beta version.

Any help will be greatly appreciated.

Thanks in advance.

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
    }*/
}
Wes Foster
  • 8,770
  • 5
  • 42
  • 62
Sayan Sarkar
  • 23
  • 1
  • 4
  • the problem is that the outlet action functions have as a parameter type AnyObject.There are two ways to fix that. Type casting them to a different type or when you ctrl drag and drop the line from the element in your storyboard to your view controller instead of anyObject choose a specific type. try that out – Korpel Sep 24 '15 at 15:50
  • So, do I choose, UIButton? Sorry, I am really a novice in Swift, just started learning a few days ago. – Sayan Sarkar Sep 24 '15 at 15:58
  • @Korpel, what's wrong with AnyObject? `sender` isn't used anyway. I often use actions with AnyObject in my code, they works ok. – kelin Sep 24 '15 at 16:00
  • @SayanSarkar, you provided to much code to analyze. Try to place breakpoints in different places and figure out where it crashes. – kelin Sep 24 '15 at 16:01
  • @IBOutlet var subjectLabel: UILabel! -- This is where the breakpoint happens – Sayan Sarkar Sep 24 '15 at 16:22

1 Answers1

3

This is a good example of a question that's not going to get good answers because you haven't been specific enough. For anyone like you who is learning, heres a couple tips on debugging and getting good help.

1) Tell everyone exactly where the problem occurred. It sounds like your app is getting terminated with a SIGSTOP and the stack trace then doesn't tell you where it occurred. But I'm not sure that's true because you only put the error in the title. State everything clearly you know in the body.

2) And don't include code that you don't know is related, just the code where the crash occurs or directly related to it. People can always ask you for more code, but the more code the harder it is to understand what you are doing.

3) If you don't know where the crash is occurring, set breakpoints in the debugger and trace till the error occurs, and give us the line. In this case I'd start in the new code you added. Usually if you know the line you'll find the problem yourself, saving you the time of writing this up.

4) If setting a breakpoints and stepping through code isn't getting you to where the crash occurred, go into the debugger breakpoints, click the + button on the bottom left of it's view (it should be the tall area on the left side of the screen when you are running with the debugger) and add an "Exception Breakpoint". Swift can't catch exceptions from Objective C code/libraries/frameworks, and this breakpoint will catch them for you and give you more info on where they occurred.

If you work on pinning down exactly where your errors occur, it often becomes easy to fix them on your own. I know this is pretty late to help you, but hoping this helps other new Swifties,

best wishes, Randy

SafeFastExpressive
  • 3,637
  • 2
  • 32
  • 39