import Foundation struct ConfigurationFile { let folder: String? let iterations: Int? let server: String? let authentication: String? /// The number of images required to include a cap in training let minimumImagesPerCap: Int? } 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) } } }