diff --git a/Reader.xcodeproj/xcshareddata/xcschemes/Reader.xcscheme b/Reader.xcodeproj/xcshareddata/xcschemes/Reader.xcscheme new file mode 100644 index 0000000..1f10bed --- /dev/null +++ b/Reader.xcodeproj/xcshareddata/xcschemes/Reader.xcscheme @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Reader/CoreData/PersistentContainer.swift b/Reader/CoreData/PersistentContainer.swift index c5ed416..68727e6 100644 --- a/Reader/CoreData/PersistentContainer.swift +++ b/Reader/CoreData/PersistentContainer.swift @@ -39,6 +39,13 @@ class PersistentContainer: NSPersistentContainer { } } + @MainActor + private func saveViewContext() async throws { + if viewContext.hasChanges { + try viewContext.save() + } + } + func lastSyncDate() async throws -> Date? { return try await backgroundContext.perform { let state = try self.backgroundContext.fetch(SyncState.fetchRequest()).first @@ -56,8 +63,8 @@ class PersistentContainer: NSPersistentContainer { } try self.backgroundContext.save() - try self.viewContext.save() } + try await self.saveViewContext() } func sync(serverGroups: [Fervor.Group], serverFeeds: [Fervor.Feed]) async throws { @@ -87,9 +94,9 @@ class PersistentContainer: NSPersistentContainer { if self.backgroundContext.hasChanges { try self.backgroundContext.save() - try self.viewContext.save() } } + try await self.saveViewContext() } func syncItems(_ syncUpdate: ItemsSyncUpdate) async throws { @@ -123,9 +130,9 @@ class PersistentContainer: NSPersistentContainer { if self.backgroundContext.hasChanges { try self.backgroundContext.save() - try self.viewContext.save() } } + try await self.saveViewContext() } }