wip
This commit is contained in:
@@ -51,6 +51,17 @@ extension PersistenceController {
|
||||
}
|
||||
}
|
||||
|
||||
func generateObjectNotInArray() -> MoodEntry {
|
||||
let newItem = MoodEntry(context: childContext)
|
||||
newItem.timestamp = Date()
|
||||
newItem.moodValue = Int16(Mood.placeholder.rawValue)
|
||||
newItem.forDate = Date()
|
||||
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: Date()))
|
||||
newItem.canEdit = false
|
||||
newItem.canDelete = false
|
||||
return newItem
|
||||
}
|
||||
|
||||
func populateTestData() {
|
||||
for idx in 1..<120 {
|
||||
let newItem = MoodEntry(context: viewContext)
|
||||
|
||||
40
Shared/Persisence/PersistenceUPDATE.swift
Normal file
40
Shared/Persisence/PersistenceUPDATE.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// PersistenceUPDATE.swift
|
||||
// Feels
|
||||
//
|
||||
// Created by Trey Tartt on 2/18/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension PersistenceController {
|
||||
@discardableResult
|
||||
public func update(entryDate: Date, withModd mood: Mood) -> Bool {
|
||||
if let entry = PersistenceController.shared.getEntry(byDate: entryDate) {
|
||||
viewContext.delete(entry)
|
||||
}
|
||||
|
||||
do {
|
||||
try PersistenceController.shared.viewContext.save()
|
||||
} catch {
|
||||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
return false
|
||||
}
|
||||
|
||||
add(mood: mood, forDate: entryDate, entryType: .listView)
|
||||
|
||||
do {
|
||||
try viewContext.save()
|
||||
return true
|
||||
} catch {
|
||||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user