Я пытаюсь написать простое приложение для быстрого угадывания для iPhone. Код работает успешно, отображая «Сборка выполнена успешно». Однако я продолжаю получать это сообщение для определенной строки: «Поток 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!"}
}
}
}