diff --git a/LeStorage/StoredCollection+Sync.swift b/LeStorage/StoredCollection+Sync.swift index d83cf14..2368fb2 100644 --- a/LeStorage/StoredCollection+Sync.swift +++ b/LeStorage/StoredCollection+Sync.swift @@ -30,8 +30,12 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { } } + func loadDataFromServerIfAllowed() async throws { + try await self.loadDataFromServerIfAllowed(clear: false) + } + /// Retrieves the data from the server and loads it into the items array - public func loadDataFromServerIfAllowed() async throws { + public func loadDataFromServerIfAllowed(clear: Bool = false) async throws { guard !(self is StoredSingleton) else { throw StoreError.cannotSyncCollection(name: self.resourceName) } @@ -39,6 +43,9 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { let items: [T] = try await self.store.getItems() if items.count > 0 { DispatchQueue.main.async { + if clear { + self.clear() + } self.addOrUpdateNoSync(contentOfs: items) } }