make sure coredata uses the right thread
This commit is contained in:
parent
3feb27848a
commit
8714009cfa
2 changed files with 34 additions and 33 deletions
|
|
@ -101,8 +101,10 @@ class Store: ObservableObject {
|
|||
}
|
||||
|
||||
func delete(subscription: Subscription) {
|
||||
context.delete(subscription)
|
||||
try? context.save()
|
||||
context.performAndWait {
|
||||
context.delete(subscription)
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
|
@ -130,35 +132,41 @@ class Store: ObservableObject {
|
|||
}
|
||||
|
||||
func delete(notification: Notification) {
|
||||
Log.d(Store.tag, "Deleting notification \(notification.id ?? "")")
|
||||
context.delete(notification)
|
||||
try? context.save()
|
||||
context.performAndWait {
|
||||
Log.d(Store.tag, "Deleting notification \(notification.id ?? "")")
|
||||
context.delete(notification)
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
|
||||
func delete(notifications: Set<Notification>) {
|
||||
Log.d(Store.tag, "Deleting \(notifications.count) notification(s)")
|
||||
do {
|
||||
notifications.forEach { notification in
|
||||
context.delete(notification)
|
||||
context.performAndWait {
|
||||
Log.d(Store.tag, "Deleting \(notifications.count) notification(s)")
|
||||
do {
|
||||
notifications.forEach { notification in
|
||||
context.delete(notification)
|
||||
}
|
||||
try context.save()
|
||||
} catch let error {
|
||||
Log.w(Store.tag, "Cannot delete notification(s)", error)
|
||||
rollbackAndRefresh()
|
||||
}
|
||||
try context.save()
|
||||
} catch let error {
|
||||
Log.w(Store.tag, "Cannot delete notification(s)", error)
|
||||
rollbackAndRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
func delete(allNotificationsFor subscription: Subscription) {
|
||||
guard let notifications = subscription.notifications else { return }
|
||||
Log.d(Store.tag, "Deleting all \(notifications.count) notification(s) for subscription \(subscription.urlString())")
|
||||
do {
|
||||
notifications.forEach { notification in
|
||||
context.delete(notification as! Notification)
|
||||
context.performAndWait {
|
||||
guard let notifications = subscription.notifications else { return }
|
||||
Log.d(Store.tag, "Deleting all \(notifications.count) notification(s) for subscription \(subscription.urlString())")
|
||||
do {
|
||||
notifications.forEach { notification in
|
||||
context.delete(notification as! Notification)
|
||||
}
|
||||
try context.save()
|
||||
} catch let error {
|
||||
Log.w(Store.tag, "Cannot delete notification(s)", error)
|
||||
rollbackAndRefresh()
|
||||
}
|
||||
try context.save()
|
||||
} catch let error {
|
||||
Log.w(Store.tag, "Cannot delete notification(s)", error)
|
||||
rollbackAndRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -206,23 +206,17 @@ struct NotificationListView: View {
|
|||
}
|
||||
|
||||
private func unsubscribe() {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
subscriptionManager.unsubscribe(subscription)
|
||||
}
|
||||
subscriptionManager.unsubscribe(subscription)
|
||||
delegate.selectedBaseUrl = nil
|
||||
}
|
||||
|
||||
private func deleteAll() {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
store.delete(allNotificationsFor: subscription)
|
||||
}
|
||||
store.delete(allNotificationsFor: subscription)
|
||||
}
|
||||
|
||||
private func deleteSelected() {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
store.delete(notifications: selection)
|
||||
selection = Set<Notification>()
|
||||
}
|
||||
store.delete(notifications: selection)
|
||||
selection = Set<Notification>()
|
||||
editMode = .inactive
|
||||
}
|
||||
|
||||
|
|
@ -346,4 +340,3 @@ struct NotificationListView_Previews: PreviewProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue