我一直在Xcode中获得线程1:信号SIGABRT

时间:2015-07-23 18:14:07

标签: iphone swift signals sigabrt xcode6.1.1

我正在尝试为iPhone编写一个简单的猜测swift应用程序。代码成功运行,显示“Build Succeeded”。但是,我不断收到特定行的消息:“线程1:信号SIGABRT”。

该行包含“num + = Int((rand()%4)+ 1)”,在游乐场中可以正常工作。

有人能告诉我如何解决这个问题吗?

import UIKit

class ViewController: UIViewController {


var num = 0


@IBOutlet var GuessField: UITextField!


@IBOutlet var ResultLabel: UILabel!


@IBOutlet var ScoreLabel: UILabel!


@IBAction func NewGameButton(sender: UIBarButtonItem) {


num += Int( (rand()%4) + 1)

    /* Random numbers generated at num range from 1 to 4, which respectively
    correspond to strings BMW, Mercedes, Lamborgini, and Ford. */

}




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.
}

@IBAction func ResultButton(sender: AnyObject) {

    if GuessField.text == "BMW" {
        if num == 1 {ResultLabel.text = "You Win!"}
        else {ResultLabel.text = "Try Again!"}

    }

    if GuessField.text == "Mercedes" {
        if num == 2 {ResultLabel.text = "You Win!"}
        else {ResultLabel.text = "Try Again!"}

    }


    if GuessField.text == "Lamborgini" {
        if num == 3 {ResultLabel.text = "You Win!"}
        else {ResultLabel.text = "Try Again!"}

    }

    if GuessField.text == "Ford" {
        if num == 4 {ResultLabel.text = "You Win!"}
        else {ResultLabel.text = "Try Again!"}

    }


}

}

2 个答案:

答案 0 :(得分:1)

尝试说出num = Int( (rand()%4) + 1)而不是num += Int( (rand()%4) + 1)

答案 1 :(得分:1)

如果您创建了一个控件并向视图控制器添加了一个插座连接,然后在从控制器的连接中正确删除插座连接之前从页面中删除了控件,那么"线程1:信号SIGABRT& #34;错误发生。我以前遇到过同样的问题。它也可能是说你的类不符合KeyValueCoding或其他东西。在删除控件之前,请确保清除控件的所有连接。