// // CoreDataStorage.swift // Notes // // Created by Laurent Morvillier on 21/09/2022. // import Foundation class CoreDataStorage { static var main: CoreDataStorage = CoreDataStorage() fileprivate var _timer: Timer? = nil func requestStorage(note: Note, content: String) { note.content = content note.lastEditDate = Date() self._timer?.invalidate() self._timer = Timer.scheduledTimer(timeInterval: idleTimeBeforeSaving, target: self, selector: #selector(self._storageRequested), userInfo: nil, repeats: false) } @objc fileprivate func _storageRequested() { AppDelegate.shared.saveContext() } }