-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateItemViewController.swift
More file actions
73 lines (49 loc) · 1.72 KB
/
UpdateItemViewController.swift
File metadata and controls
73 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// UpdateItemViewController.swift
// CoreDataExample
//
// Created by Farhan Syed on 4/16/17.
// Copyright © 2017 Farhan Syed. All rights reserved.
//
import UIKit
class UpdateItemViewController: UIViewController, UITextViewDelegate {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var item: Item!
@IBOutlet weak var entryText: UITextView!
@IBAction func dismiss(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
@IBAction func updateAction(_ sender: Any) {
guard let newEntry = entryText.text else {
return
}
item.name = newEntry
(UIApplication.shared.delegate as! AppDelegate).saveContext()
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
entryText!.delegate = self
entryText!.becomeFirstResponder()
configureEntryData(entry: item)
print(item)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func configureEntryData(entry: Item) {
guard let text = entry.name else {
return
}
entryText!.text = text
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if (text == "\n") {
textView.resignFirstResponder()
return false
}
return true
}
}