This commit is contained in:
Trey t
2022-02-10 11:54:32 -06:00
parent 4b4e69d752
commit f66caf93dd
8 changed files with 41 additions and 15 deletions

View File

@@ -34,7 +34,7 @@ class PersistenceController {
return data.first
}
public func add(mood: Mood, forDate date: Date) {
public func add(mood: Mood, forDate date: Date, entryType: EntryType) {
if let existingEntry = getEntry(byDate: date) {
viewContext.delete(existingEntry)
try? viewContext.save()
@@ -47,6 +47,7 @@ class PersistenceController {
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: date))
newItem.canEdit = true
newItem.canDelete = true
newItem.entryType = Int16(entryType.rawValue)
do {
try viewContext.save()
@@ -163,7 +164,7 @@ class PersistenceController {
let existingEntriesSet = Set(existingEntries)
let missing = Array(allDatesSet.subtracting(existingEntriesSet)).sorted(by: >)
for date in missing {
add(mood: .missing, forDate: date)
add(mood: .missing, forDate: date, entryType: .listView)
}
}
}
@@ -219,6 +220,8 @@ class PersistenceController {
for description in container.persistentStoreDescriptions {
description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description.setOption(true as NSNumber, forKey: NSMigratePersistentStoresAutomaticallyOption)
description.setOption(true as NSNumber, forKey: NSInferMappingModelAutomaticallyOption)
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in