application iOS de notes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
notes/Notes/Storage/CoreDataStorage.swift

30 lines
715 B

//
// 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() {
PersistenceController.shared.save()
}
}