I tried several answers from different posts but none of them solved my problem.
Situation I am in:
- The project is called XcodeTests and the only target it has is XcodeTests
- I have a
my_file.txtfile at<ProjectRoot>/XcodeTests/res/ - Upon creating
my_file.txt, I made sure that target XcodeTests was selected - Both
resfolder andmy_file.txtexists in storage directories confirmed by Finder - In Build Phase of XcodeTests, CopyBundleResources does include
my_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?