From 568d822b48d908019a4dc335d0a188d888d87436 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 26 Dec 2024 09:20:21 -0500 Subject: [PATCH] Switched to relative input file reading Originally, input files were compiled into the bundle. Now, they are read from `Sources/Data/DayXX.txt`. --- Package.swift | 2 +- Sources/AdventDay.swift | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index e4e4241..5ca9907 100644 --- a/Package.swift +++ b/Package.swift @@ -28,7 +28,7 @@ let package = Package( .executableTarget( name: "AdventOfCode", dependencies: dependencies, - resources: [.copy("Data")] + exclude: ["Data/"] ), .testTarget( name: "AdventOfCodeTests", diff --git a/Sources/AdventDay.swift b/Sources/AdventDay.swift index c7227b0..773d801 100644 --- a/Sources/AdventDay.swift +++ b/Sources/AdventDay.swift @@ -61,12 +61,9 @@ extension AdventDay { static func loadData(challengeDay: Int) -> String { let dayString = String(format: "%02d", challengeDay) let dataFilename = "Day\(dayString)" - let dataURL = Bundle.module.url( - forResource: dataFilename, - withExtension: "txt", - subdirectory: "Data") + let dataURL = URL(fileURLWithPath: "Sources/Data/\(dataFilename).txt", isDirectory: false, relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true)) - guard let dataURL, + guard FileManager.default.fileExists(atPath: dataURL.path()), let data = try? String(contentsOf: dataURL, encoding: .utf8) else { fatalError("Couldn't find file '\(dataFilename).txt' in the 'Data' directory.")