mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Fix clearUserCollections bug
This commit is contained in:
parent
300d4f30b4
commit
d7167bc72a
@ -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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user