Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13780097
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/Shared/PostCollection/CollectionListModel.swift b/Shared/PostCollection/CollectionListModel.swift
index 741cee7..c5ff71f 100644
--- a/Shared/PostCollection/CollectionListModel.swift
+++ b/Shared/PostCollection/CollectionListModel.swift
@@ -1,37 +1,38 @@
import SwiftUI
import CoreData
class CollectionListModel: ObservableObject {
@Published var userCollections = [WFACollection]()
init() {
loadCachedUserCollections()
}
func loadCachedUserCollections() {
let request = WFACollection.createFetchRequest()
let sort = NSSortDescriptor(key: "title", ascending: true)
request.sortDescriptors = [sort]
userCollections = []
do {
let cachedCollections = try PersistenceManager.persistentContainer.viewContext.fetch(request)
userCollections.append(contentsOf: cachedCollections)
} catch {
print("Error: Failed to fetch cached user collections.")
}
}
func clearUserCollection() {
- // Make sure the userCollections property is properly populated.
- // FIXME: Without this, sometimes the userCollections array is empty.
- loadCachedUserCollections()
+ userCollections = []
+ let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "WFACollection")
+ let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
- for userCollection in userCollections {
- PersistenceManager.persistentContainer.viewContext.delete(userCollection)
+ do {
+ try PersistenceManager.persistentContainer.persistentStoreCoordinator.execute(
+ deleteRequest, with: PersistenceManager.persistentContainer.viewContext
+ )
+ } catch {
+ print("Error: Failed to purge cached collections.")
}
- PersistenceManager().saveContext()
-
- userCollections = []
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Jan 30, 9:31 AM (6 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3610417
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment