Caps-Train/Sources/ConfigurationFile.swift
2023-10-23 16:49:56 +02:00

37 lines
841 B
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 {
throw TrainingError.configurationFileMissing(url)
}
let data: Data
do {
data = try Data(contentsOf: url)
} catch {
throw TrainingError.configurationFileUnreadable(url, error)
}
do {
self = try JSONDecoder().decode(ConfigurationFile.self, from: data)
} catch {
throw TrainingError.configurationFileDecodingFailed(url, error)
}
}
}