Skip to content

Instantly share code, notes, and snippets.

@bobleesj
Created December 28, 2016 15:02
Show Gist options
  • Save bobleesj/431a59103b2aecab1ebb23e1ef7cc1ea to your computer and use it in GitHub Desktop.
Save bobleesj/431a59103b2aecab1ebb23e1ef7cc1ea to your computer and use it in GitHub Desktop.
class AddTaskViewController: UIViewController {
@IBOutlet weak var taskTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func buttonTapped(_ sender: UIButton) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let task = Task(context: context) // Link Task & Context
task.name = taskTextField.text!
// Save the data to coredata
(UIApplication.shared.delegate as! AppDelegate).saveContext()
let _ = navigationController?.popViewController(animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment