40 lines
1.1 KiB
Swift
40 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
struct ConfigurationFile {
|
|
|
|
let contentFolder: String?
|
|
|
|
let trainingIterations: Int?
|
|
|
|
let serverPath: String?
|
|
|
|
let authenticationToken: String?
|
|
}
|
|
|
|
extension ConfigurationFile: Decodable {
|
|
|
|
}
|
|
|
|
extension ConfigurationFile {
|
|
|
|
init(at url: URL) throws {
|
|
guard FileManager.default.fileExists(atPath: url.path) else {
|
|
print("[ERROR] No configuration at \(url.absoluteURL.path)")
|
|
throw TrainingError.configurationFileMissing
|
|
}
|
|
let data: Data
|
|
do {
|
|
data = try Data(contentsOf: url)
|
|
} catch {
|
|
print("[ERROR] Failed to load configuration data at \(url.absoluteURL.path): \(error)")
|
|
throw TrainingError.configurationFileUnreadable
|
|
}
|
|
do {
|
|
self = try JSONDecoder().decode(ConfigurationFile.self, from: data)
|
|
} catch {
|
|
print("[ERROR] Failed to decode configuration at \(url.absoluteURL.path): \(error)")
|
|
throw TrainingError.configurationFileDecodingFailed
|
|
}
|
|
}
|
|
}
|