// // StoredObject.swift // LeStorage // // Created by Laurent Morvillier on 03/05/2024. // import Foundation /// A class extending the capabilities of StoredCollection but supposedly manages only one item public class StoredSingleton: StoredCollection { /// Sets the singleton to the collection without synchronizing it public func setItemNoSync(_ instance: T) { self.setSingletonNoSync(instance: instance) } /// updates the existing singleton public func update() throws { if let item = self.item() { try self.addOrUpdate(instance: item) } } /// Returns the singleton public func item() -> T? { return self.items.first } // MARK: - Protects from use public override func addOrUpdate(contentOfs sequence: any Sequence) throws { fatalError("method unavailable for StoredSingleton, use update") } }