|
|
|
|
@ -23,6 +23,7 @@ protocol CollectionHolder { |
|
|
|
|
protocol SomeCollection: CollectionHolder, Identifiable { |
|
|
|
|
var resourceName: String { get } |
|
|
|
|
var synchronized: Bool { get } |
|
|
|
|
var hasLoadedLocally: Bool { get } |
|
|
|
|
|
|
|
|
|
func allItems() -> [any Storable] |
|
|
|
|
|
|
|
|
|
@ -72,7 +73,10 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
|
|
|
|
|
/// Denotes a collection that loads and writes asynchronously |
|
|
|
|
fileprivate var asynchronousIO: Bool = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Indicates if the collection has loaded locally, with or without a file |
|
|
|
|
fileprivate(set) public var hasLoadedLocally: Bool = false |
|
|
|
|
|
|
|
|
|
/// Indicates if the collection has loaded objects from the server |
|
|
|
|
fileprivate(set) public var hasLoadedFromServer: Bool = false |
|
|
|
|
|
|
|
|
|
@ -136,6 +140,9 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
|
|
|
|
|
/// Decodes the json file into the items array |
|
|
|
|
fileprivate func _decodeJSONFile() throws { |
|
|
|
|
|
|
|
|
|
defer { self.hasLoadedLocally = true } |
|
|
|
|
|
|
|
|
|
let fileURL = try self._store.fileURL(type: T.self) |
|
|
|
|
|
|
|
|
|
if FileManager.default.fileExists(atPath: fileURL.path()) { |
|
|
|
|
@ -228,6 +235,7 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Sends a POST request for the instance, and changes the collection to perform a write |
|
|
|
|
public func writeChangeAndInsertOnServer(instance: T) { |
|
|
|
|
defer { |
|
|
|
|
self._hasChanged = true |
|
|
|
|
|