fix micro storage
multistore
Razmig Sarkissian 2 years ago
parent d38b619cb8
commit 64572ec7f3
  1. 9
      LeStorage/MicroStorage.swift

@ -14,13 +14,14 @@ public protocol MicroStorable : Codable {
public class MicroStorage<T : MicroStorable> {
fileprivate(set) var item: T
public fileprivate(set) var item: T
init() {
public init() {
var instance: T? = nil
do {
let url = try FileUtils.pathForFileInDocumentDirectory(T.fileName)
if FileManager.default.fileExists(atPath: url.absoluteString) {
let fileExists = FileManager.default.fileExists(atPath: url.path())
if fileExists {
let jsonString = try FileUtils.readDocumentFile(fileName: T.fileName)
if let decoded: T = try jsonString.decode() {
instance = decoded
@ -33,7 +34,7 @@ public class MicroStorage<T : MicroStorable> {
self.item = instance ?? T()
}
func update(handler: (T) -> ()) {
public func update(handler: (T) -> ()) {
handler(self.item)
self._write()
}

Loading…
Cancel
Save