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) } } }