From fe78bbbe43d616ed71e3ad0f6aa617fa4733049c Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 3 Jul 2024 11:46:52 +0200 Subject: [PATCH] Fix potential item change in background thread --- LeStorage/StoredCollection.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index 9fadeb1..f66ba0b 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -433,7 +433,9 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti Task { do { if let result = try await self._store.sendInsertion(instance) { - self._hasChanged = instance.copyFromServerInstance(result) + DispatchQueue.main.async { + self._hasChanged = instance.copyFromServerInstance(result) + } } } catch { Logger.error(error)