diff --git a/Enigma/MachineViewController.swift b/Enigma/MachineViewController.swift index 06807e6..3e32e77 100644 --- a/Enigma/MachineViewController.swift +++ b/Enigma/MachineViewController.swift @@ -14,8 +14,54 @@ class MachineViewController: UIViewController, UITextFieldDelegate { override func viewDidLoad() { super.viewDidLoad() + inputTextField.delegate = self + //outputTextField.delegate = self } // MARK: - UITextFieldDelegate + + func textFieldDidEndEditing(textField: UITextField) { + print("textFieldDidEndEditing") + } + + func textFieldShouldBeginEditing(textField: UITextField) -> Bool { + print("textFieldShouldBeginEditing") + return true + } + + func textFieldShouldEndEditing(textField: UITextField) -> Bool { + print("textFieldShouldEndEditing") + return true + } + + 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()) + } catch let error { + print("Error setting up machine: \(error)") + return true + } + if let inputText = textField.text { + do { + outputTextField.text = try machine.encode(inputText) + } catch let error { + print("Error encoding: \(error)") + return true + } + } + return false + } + return true + } + + func textFieldShouldClear(textField: UITextField) -> Bool { + print("textFieldShouldClear") + if textField === inputTextField { + return true + } + return false + } } diff --git a/Enigma/ViewController.swift b/Enigma/ViewController.swift deleted file mode 100644 index eb25bef..0000000 --- a/Enigma/ViewController.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// ViewController.swift -// Enigma -// -// Created by Eryn Wells on 2015-07-18. -// Copyright © 2015 Eryn Wells. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - 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. - } - - -} -