【发布时间】:2022-11-27 06:16:40
【问题描述】:
我尝试了来自不同帖子的几个答案,但没有一个解决了我的问题。
我所处的情况:
- 我在
<ProjectRoot>/XcodeTests/res/有一个my_file.txt文件 - 创建
my_file.txt时,我确保目标Xcode测试被选中 -
res文件夹和my_file.txt都存在于Finder确认的存储目录中 - 在建造阶段Xcode测试,复制捆绑资源确实包括
my_file.txt
以下代码抛出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")
}
我应该怎么做才能让Bundle.main.url 找到my_file.txt?
【问题讨论】:
标签: ios swift xcode macos bundle