forked from keirstenmachine/ios-challenge-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteDetailViewController.swift
More file actions
48 lines (37 loc) · 1.08 KB
/
NoteDetailViewController.swift
File metadata and controls
48 lines (37 loc) · 1.08 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
//
// NoteDetailViewController.swift
// Notes
//
// Created by Jordan Fraughton on 5/18/17.
// Copyright © 2017 DevMountain. All rights reserved.
//
import UIKit
class NoteDetailViewController: UIViewController {
// Actions
@IBAction func saveButtonTapped(_ sender: Any) {
guard let text = noteTextView.text else { return }
// Updating a note and adding a new note
if let note = self.note {
NoteController.shared.update(note: note, text: text)
} else {
NoteController.shared.addNewNoteWith(text: text)
}
let _ = self.navigationController?.popViewController(animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
updateViews()
}
// Private
private func updateViews() {
guard let note = note else { return }
noteTextView.text = note.text
}
// Properties
@IBOutlet weak var noteTextView: UITextView!
var note: Note? {
didSet {
if isViewLoaded { updateViews() }
}
}
}