0

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

enter image description here

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!")
    }
}

}
isabella
  • 151
  • 4
  • 15
  • 4
    I only see classes... Classes everywhere! Please only use capitalized names for class names :) – Eendje Mar 03 '16 at 05:47
  • I don't understand...This is the ViewController.swift class. – isabella Mar 03 '16 at 11:50
  • The naming convention is: classes, structs and enums start with a capital letter. Variables / properties and functions / methods with a lowercase letter. You're naming everything capitalized which is very hard to read. – vadian Mar 03 '16 at 12:37

0 Answers0