Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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
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
}
}
@mikewarcholik

This comment has been minimized.

Copy link

@mikewarcholik mikewarcholik commented Jan 9, 2015

Thanks! I am not new to programming, but am new to iOS, and was going through exactly that textbook...figured it would be a worthwhile challenge to take the tutorials and write them in Swift. I laughed when I saw this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.