Fix clearUserCollections bug

This commit is contained in:
Angelo Stavrow 2020-09-09 10:59:44 -04:00
parent 300d4f30b4
commit d7167bc72a
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -23,15 +23,16 @@ class CollectionListModel: ObservableObject {
}
func clearUserCollection() {
// Make sure the userCollections property is properly populated.
// FIXME: Without this, sometimes the userCollections array is empty.
loadCachedUserCollections()
for userCollection in userCollections {
PersistenceManager.persistentContainer.viewContext.delete(userCollection)
}
PersistenceManager().saveContext()
userCollections = []
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "WFACollection")
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
do {
try PersistenceManager.persistentContainer.persistentStoreCoordinator.execute(
deleteRequest, with: PersistenceManager.persistentContainer.viewContext
)
} catch {
print("Error: Failed to purge cached collections.")
}
}
}