SpacePod 37 PodList Refactor
The changes depicted in 36 result in a failure to load on first launch. The following changes to PodListView fix the issue, and begin the work of decluttering our PodListView
.
Goals
- Fix first launch bug introduced last time
- Move CoreData related functions to
Persistence
Fix Bug
PodListView
.task {
if pods.isEmpty { await getOld() }
}
private func getOld() async {
let to = pods.last?.date?.previous(1) ?? Date()
Clean Up
- Cut and paste
delete
andsave
intoPersistence
. - prepend
viewContext
withcontainer.
func delete(_ pod: Pod) {
container.viewContext.delete(pod)
save()
}
func save() {
do {
try container.viewContext.save()
} catch {
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
}
save()
toPersistenceController.shared.save()
delete()
toPersistenceController.shared.delete(pod)