-
-
Save minorbug/2cb6657c30baae732a85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// Quiz | |
// | |
// Created by John Regner on 7/26/14. | |
// Copyright (c) 2014 In Your Dreams Software. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var questionField: UILabel! | |
@IBOutlet weak var answerField: UILabel! | |
var questions: [String] = Array() | |
var answers: [String] = Array() | |
var currentQuestionIndex: Int | |
required init(coder aDecoder: NSCoder! ){ | |
currentQuestionIndex = 0 | |
questions += " What is 7 + 7?" | |
answers += " 14" | |
questions += " What is the capital of Vermont?" | |
answers += " Montpelier" | |
questions += " From what is cognac made?" | |
answers += " Grapes" | |
super.init(coder: aDecoder) | |
} | |
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 showQuestion(sender: AnyObject) { | |
++currentQuestionIndex | |
if currentQuestionIndex == questions.count{ | |
currentQuestionIndex = 0 | |
} | |
let question = questions[currentQuestionIndex] | |
NSLog("displaying question: %@", question) | |
questionField.text = question | |
answerField.text = "???" | |
} | |
@IBAction func showAnswer(sender: AnyObject) { | |
let answer = answers[currentQuestionIndex] | |
answerField.text = answer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment