Rename ViewController -> MachineViewController
This commit is contained in:
parent
358c67cdfb
commit
c96c0bd0fc
2 changed files with 46 additions and 25 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue