|
|
|
|
@ -183,8 +183,12 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Retrieves the data from the server and loads it into the items array |
|
|
|
|
public 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(clear: Bool = false) async throws { |
|
|
|
|
guard self.synchronized, !(self is StoredSingleton<T>) else { |
|
|
|
|
throw StoreError.cannotSyncCollection(name: self.resourceName) |
|
|
|
|
} |
|
|
|
|
@ -192,6 +196,9 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
let items: [T] = try await self._store.getItems() |
|
|
|
|
if items.count > 0 { |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
if clear { |
|
|
|
|
self.clear() |
|
|
|
|
} |
|
|
|
|
self._addOrUpdate(contentOfs: items, shouldSync: false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|