From b0c03a7651c20dc06f60578c11687a643549b130 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 26 Mar 2024 13:56:46 +0100 Subject: [PATCH] Adds a delete sequence method --- LeStorage/StoredCollection.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index 9577538..a67821a 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -178,7 +178,22 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti } - /// Inserts the whole sequence into the items array, no updates + /// Deletes all items of the sequence by id + public func delete(contentOfs sequence: any Sequence) throws { + + defer { + self._hasChanged = true + } + + for instance in sequence { + try instance.deleteDependencies() + self.items.removeAll { $0.id == instance.id } + self._index?.removeValue(forKey: instance.stringId) + try self._sendDeletionIfNecessary(instance) + } + } + + /// Inserts or updates all items in the sequence public func addOrUpdate(contentOfs sequence: any Sequence) throws { defer { self._hasChanged = true