Settings: Fix how modified source lists are saved

Since an existing source list is fetched from the ViewContext, save
in the scope of that context. This will fix any fetching issues
when grabbing sources from the new URL.

Signed-off-by: kingbri <bdashore3@gmail.com>
This commit is contained in:
kingbri 2022-08-15 21:18:33 -04:00 committed by kingbri
parent 3c6ce0bb94
commit 0401d220dc
2 changed files with 8 additions and 2 deletions

View file

@ -46,6 +46,10 @@ struct PersistenceController {
backgroundContext.automaticallyMergesChangesFromParent = true
backgroundContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
try? backgroundContext.setQueryGenerationFrom(.current)
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
try? container.viewContext.setQueryGenerationFrom(.current)
}
func save(_ context: NSManagedObjectContext? = nil) {

View file

@ -274,6 +274,8 @@ public class SourceManager: ObservableObject {
existingSourceList.urlString = sourceUrl
existingSourceList.name = rawResponse.name
existingSourceList.author = rawResponse.author
try PersistenceController.shared.container.viewContext.save()
} else {
let sourceListRequest = SourceList.fetchRequest()
let urlPredicate = NSPredicate(format: "urlString == %@", sourceUrl)
@ -293,9 +295,9 @@ public class SourceManager: ObservableObject {
newSourceUrl.urlString = sourceUrl
newSourceUrl.name = rawResponse.name
newSourceUrl.author = rawResponse.author
}
try backgroundContext.save()
try backgroundContext.save()
}
return true
} catch {