|
|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
|
|
import Foundation |
|
|
|
|
import UIKit |
|
|
|
|
import CoreData |
|
|
|
|
|
|
|
|
|
class NoteViewController : UIViewController, UITextViewDelegate { |
|
|
|
|
|
|
|
|
|
@ -37,7 +38,9 @@ class NoteViewController : UIViewController, UITextViewDelegate { |
|
|
|
|
|
|
|
|
|
/// Store notifications |
|
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(self._storeRemoteChange(notification:)), name: .NSPersistentStoreCoordinatorStoresDidChange, object: nil) |
|
|
|
|
print("REGISTER") |
|
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(self._storeRemoteChange(notification:)), name: NSPersistentCloudKitContainer.eventChangedNotification, object: nil) |
|
|
|
|
|
|
|
|
|
/// Keyboard notifications |
|
|
|
|
|
|
|
|
|
@ -63,7 +66,11 @@ class NoteViewController : UIViewController, UITextViewDelegate { |
|
|
|
|
request.sortDescriptors = [NSSortDescriptor(key: "lastEditDate", ascending: false)] |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
self.note = try AppDelegate.viewContext.fetch(request).first |
|
|
|
|
let notes = try AppDelegate.viewContext.fetch(request) |
|
|
|
|
|
|
|
|
|
print("notes in store : \(notes.count)") |
|
|
|
|
|
|
|
|
|
self.note = notes.first |
|
|
|
|
self.textView.text = self.note?.content |
|
|
|
|
} catch { |
|
|
|
|
print("Fetch error = \(error)") |
|
|
|
|
@ -73,8 +80,10 @@ class NoteViewController : UIViewController, UITextViewDelegate { |
|
|
|
|
|
|
|
|
|
@objc fileprivate func _storeRemoteChange(notification: Notification) { |
|
|
|
|
print("_storeRemoteChange...") |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
self._loadLastNote() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func textViewDidChange(_ textView: UITextView) { |
|
|
|
|
PreferencesStorage.main.requestStorage(filename: "main.txt", content: textView.text) |
|
|
|
|
@ -155,4 +164,8 @@ class NoteViewController : UIViewController, UITextViewDelegate { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
deinit { |
|
|
|
|
NotificationCenter.default.removeObserver(self) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|