|
|
|
|
@ -19,13 +19,17 @@ class MicroStorage<T : MicroStorable> { |
|
|
|
|
init() { |
|
|
|
|
var instance: T? = nil |
|
|
|
|
do { |
|
|
|
|
let jsonString = try FileUtils.readDocumentFile(fileName: T.fileName) |
|
|
|
|
if let decoded: T = try jsonString.decode() { |
|
|
|
|
instance = decoded |
|
|
|
|
let url = try FileUtils.directoryURLForFileName(T.fileName) |
|
|
|
|
if FileManager.default.fileExists(atPath: url.absoluteString) { |
|
|
|
|
let jsonString = try FileUtils.readDocumentFile(fileName: T.fileName) |
|
|
|
|
if let decoded: T = try jsonString.decode() { |
|
|
|
|
instance = decoded |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.item = instance ?? T() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|