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 Finder 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
?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.