I have yet another error, its the common swift error
Thread 1: signal SIGABRT
I know how to fix this error. Here is my recent question. Can't resolve error: Thread 1: signal SIGABRT in swift XCODE
But now I am making a new project, and I got this error! So I tried to fix it, I thought I got it - but I didn't.. I have checked all my outlets and everything, But there is no trace of where this is coming from...
Here is my code:
import 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
}
}
Check that your UIImage names are the EXACT same names as the ones in your xcassets folder.
Instead of using the helloWorldTimer
, write this at the top of your class, underneath your outlets:
var helloWorldTimer = Timer()
And then inside of your viewDidLoad
, add:
helloWorldTimer = Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: Selector(("spawnMonstor")), userInfo: nil, repeats: true)