I am new to iso programming. I am trying to create a small quiz in the app on a view controller. It has 1 label and 4 buttons. I am getting the
EXC_BAD_INSTRUCTION
at the QLabel.text = Questions[QNumber].Question
. I have deleted the label and buttons on the storyboard and then connected them to the ViewCOntroller.swift and I am still getting the error.
It also says:
QLabel = nil
and Buttons = nil
the code:
import UIKit
struct Question {
var Question: String!
var Answers: [String]!
var Answer: Int!
}
class ViewController: UIViewController {
@IBOutlet weak var QLabel: UILabel!
@IBOutlet var Buttons: [UIButton]!
var Questions = [Question]()
var QNumber = Int()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Questions = [Question(Question: "enter", Answers: ["aaa", "bbb", "ccc", "ddd"], Answer: 2)]
PickQuestion()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func PickQuestion(){
if Questions.count > 0{
QNumber = 0
QLabel.text = Questions[QNumber].Question
for i in 0..<Buttons.count{
Buttons[i].setTitle(Questions[QNumber].Answers[i], forState: UIControlState.Normal)
}
Questions.removeAtIndex(QNumber)
}
else{
NSLog("Done!")
}
}
}