UI that works! It encodes strings!

This commit is contained in:
Eryn Wells 2015-07-21 21:12:51 -07:00
parent 949ef629d3
commit 00fbebcc1e
2 changed files with 46 additions and 3 deletions

View file

@ -11,6 +11,13 @@ import UIKit
class MachineViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var inputTextField: UITextField!
@IBOutlet weak var outputTextField: UITextField!
@IBOutlet var rotorPositionLabels: [UILabel]!
var machine: Machine! = nil {
didSet {
updateRotorLabels()
}
}
override func viewDidLoad() {
super.viewDidLoad()
@ -36,9 +43,11 @@ class MachineViewController: UIViewController, UITextFieldDelegate {
func textFieldShouldReturn(textField: UITextField) -> Bool {
if textField === inputTextField {
var machine: Machine! = nil
do {
machine = Machine(rotors: [try Rotor(.EnigmaI), try Rotor(.EnigmaII), try Rotor(.EnigmaIII)], reflector: try Reflector(.EnigmaB), plugboard: Plugboard())
machine.rotors[0].notch = 17
machine.rotors[1].notch = 5
machine.rotors[2].notch = 22
} catch let error {
print("Error setting up machine: \(error)")
return true
@ -51,6 +60,7 @@ class MachineViewController: UIViewController, UITextFieldDelegate {
return true
}
}
updateRotorLabels()
return false
}
return true
@ -63,5 +73,11 @@ class MachineViewController: UIViewController, UITextFieldDelegate {
}
return false
}
private func updateRotorLabels() {
for (idx, rotor) in machine.rotors.enumerate() {
rotorPositionLabels[idx].text = String(rotor.position)
}
}
}