I tried several answers from different posts but none of them solved my problem.
Situation I am in:
my_file.txt
file at <ProjectRoot>/XcodeTests/res/
my_file.txt
, I made sure that target XcodeTests was selectedres
folder and my_file.txt
exists in storage directories confirmed by Findermy_file.txt
The following code throws Fatal error: Couldn't find requested file
:
import Foundation
guard let myFileURL = Bundle.main.url(forResource: "my_file", withExtension: "txt")
else
{
fatalError("Couldn't find requested file")
}
What should I do so that Bundle.main.url
can find my_file.txt
?
Turns out it's because the target itself is a command line program and does not support Copy Bundle Resources. Even tho resources can be listed there, none of them will be copied.