From 298dc6357ff416ba39b481210b75fdcc54ac7354 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 3 Jul 2024 11:35:43 +0200 Subject: [PATCH] Fix empty collection not being loaded --- LeStorage/StoredCollection.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index 9690432..9fadeb1 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -154,11 +154,15 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti if self.asynchronousIO { DispatchQueue.main.async { self._setItems(decoded) + self._setAsLoaded() } } else { self._setItems(decoded) + self._setAsLoaded() } - } + } else { + self._setAsLoaded() + } // else if self.synchronized { // Task { // do { @@ -171,10 +175,14 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti } + fileprivate func _setAsLoaded() { + self.hasLoadedLocally = true + NotificationCenter.default.post(name: NSNotification.Name.CollectionDidLoad, object: self) + } + fileprivate func _setItems(_ items: [T]) { self.items = items self._updateIndexIfNecessary() - NotificationCenter.default.post(name: NSNotification.Name.CollectionDidLoad, object: self) } /// Updates the whole index with the items array