You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
854 B
36 lines
854 B
//
|
|
// StoredObject.swift
|
|
// LeStorage
|
|
//
|
|
// Created by Laurent Morvillier on 03/05/2024.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public class StoredSingleton<T: Storable>: StoredCollection<T> {
|
|
|
|
public func setItemNoSync(_ instance: T) {
|
|
self.setSingletonNoSync(instance: instance)
|
|
}
|
|
|
|
public func update() throws {
|
|
if let item = self.item() {
|
|
try self.addOrUpdate(instance: item)
|
|
}
|
|
}
|
|
|
|
public func item() -> T? {
|
|
return self.items.first
|
|
}
|
|
|
|
// MARK: - Protects from use
|
|
|
|
// public override func addOrUpdate(instance: T) throws {
|
|
// fatalError("method unavailable for StoredSingleton")
|
|
// }
|
|
|
|
public override func addOrUpdate(contentOfs sequence: any Sequence<T>) throws {
|
|
fatalError("method unavailable for StoredSingleton, use update")
|
|
}
|
|
|
|
}
|
|
|