Skip to content

Commit

Permalink
Switched to relative input file reading
Browse files Browse the repository at this point in the history
Originally, input files were compiled into the bundle. Now, they are read from `Sources/Data/DayXX.txt`.
  • Loading branch information
BruceMcRooster committed Dec 26, 2024
1 parent b2557c1 commit 568d822
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
.executableTarget(
name: "AdventOfCode",
dependencies: dependencies,
resources: [.copy("Data")]
exclude: ["Data/"]
),
.testTarget(
name: "AdventOfCodeTests",
Expand Down
7 changes: 2 additions & 5 deletions Sources/AdventDay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit 568d822

Please sign in to comment.