diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index 1ff5bf5..61ee424 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -8,6 +8,11 @@ import Foundation import UIKit +public enum ResetOption { + case all + case synchronizedOnly +} + enum StoreError: Error { case missingService case unexpectedCollectionType(name: String) @@ -133,18 +138,28 @@ public class Store { } } - public func disconnect(resetAll: Bool = false) { + public func disconnect(resetOption: ResetOption? = nil) { try? self.service().disconnect() self._settingsStorage.update { settings in settings.username = nil settings.userId = nil } - if resetAll { + switch resetOption { + case .all: for collection in self._collections.values { collection.reset() } + case .synchronizedOnly: + for collection in self._collections.values { + if collection.synchronized { + collection.reset() + } + } + default: + break } + } public func hasToken() -> Bool { diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index 0eb65db..cce280a 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -19,6 +19,7 @@ protocol SomeCollection: Identifiable { func deleteApiCallById(_ id: String) throws func reset() func loadDataFromServerIfAllowed() throws + var synchronized: Bool { get } }