Skip to content

Instantly share code, notes, and snippets.

@loldi
Created March 16, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loldi/e932089c1cb5c07ef55e5321b508102a to your computer and use it in GitHub Desktop.
Save loldi/e932089c1cb5c07ef55e5321b508102a to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var txtInput: UITextField!
@IBOutlet weak var txtOutput: UITextView!
var items:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.txtInput.delegate = self
}
@IBAction func addItem(_ sender: Any) {
if(txtInput.text! == ""){
return
}
items.append(txtInput.text!)
txtOutput.text = ""
for item in items {
txtOutput.text.append("\(item)\n")
}
txtInput.text = ""
txtInput.resignFirstResponder()
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if(txtInput.text! == ""){
self.view.endEditing(false)
return true
}
items.append(txtInput.text!)
txtOutput.text = ""
for item in items {
txtOutput.text.append("\(item)\n")
}
txtInput.text = ""
txtInput.resignFirstResponder()
self.view.endEditing(true)
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment