I am trying to write a simple guessing swift app for iPhone. The code runs successfully, displaying "Build Succeeded". However, I keep getting this message for a particular line: "Thread 1: signal SIGABRT".
The line contains "num += Int( (rand()%4) + 1)", which works fine in a playground.
Can someone tell me how to fix this problem?
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!"}
}
}
}