From 787d0d736676b0ffb851c9f22f09241c4ef24a28 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 11 Apr 2025 09:50:08 +0200 Subject: [PATCH] adds tryPutBeforeUpdating method --- LeStorage/StoredSingleton.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/LeStorage/StoredSingleton.swift b/LeStorage/StoredSingleton.swift index 89f439d..2f3435e 100644 --- a/LeStorage/StoredSingleton.swift +++ b/LeStorage/StoredSingleton.swift @@ -27,6 +27,13 @@ public class StoredSingleton: SyncedCollection { return self.items.first } + public func tryPutBeforeUpdating(_ instance: T) async throws { + if let result = try await StoreCenter.main.service().put(instance) { + self.setItemNoSync(result) + } + } + + // MARK: - Protects from use public override func addOrUpdate(contentOfs sequence: any Sequence) {