Swift SIGABRT错误?但我解决了吗?

时间:2018-01-24 21:13:43

标签: swift xcode sigabrt

我还有另一个错误,它是常见的快速错误

Thread 1: signal SIGABRT

我知道如何修复此错误。这是我最近的问题。 Can't resolve error: Thread 1: signal SIGABRT in swift XCODE

但是现在我正在制作一个新项目,我收到了这个错误!所以我试着修理它,我以为我得到了它 - 但我没有......我已经检查了所有的插座和所有东西,但是没有迹象显示它来自哪里......

这是我的代码:

导入UIKit

class ViewController: UIViewController {
//Variables
var tempature:Int = 50
var battery:Int = 100
var monsterCount:Int = 0

//Outlets
@IBOutlet weak var BatteryLevel: UILabel!
@IBOutlet weak var TempDisplay: UILabel!

//The spy camera
@IBOutlet weak var monsterImageDisplay: UIImageView?

//The background image
@IBOutlet weak var backgroundImageShow: UIImageView!

//Functions
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    monsterImageDisplay?.isHidden = true
}

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

//The interval to keep things going
var helloWorldTimer = Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: Selector(("spawnMonstor")), userInfo: nil, repeats: true)

func spawnMonstor() {
    monsterImageDisplay?.isHidden = false
    monsterCount += 1
    if monsterCount >= 3 {
        let randomNumberBackgroundImage = arc4random_uniform(10)
        if randomNumberBackgroundImage >= 5 {
            backgroundImageShow.image = UIImage(named: "main-room-jumpTop")
        } else if randomNumberBackgroundImage <= 5 {
            backgroundImageShow.image = UIImage(named: "main-room-jumpBottom")
        }
    } else if monsterCount >= 5 {
        let alert = UIAlertController(title: "GAME OVER", message: "Sorry! You died...", preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "Okay..", style: UIAlertActionStyle.default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
}


//The shock rooms button

@IBAction func ShockRooms(_ sender: Any) { monsterImageDisplay?.isHidden = true
}

}

1 个答案:

答案 0 :(得分:0)

  1. 检查您的UIImage名称是否与xcassets文件夹中的 EXACT 名称相同。

  2. 不要使用helloWorldTimer,而是将其写在班级的顶部,在您的媒体下方:

  3. var helloWorldTimer = Timer()

    然后在viewDidLoad内添加:

    helloWorldTimer = Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: Selector(("spawnMonstor")), userInfo: nil, repeats: true)