我正在尝试在新应用程序中读取文本文件,但当它运行时找不到该文件。
我不确定应该将文件放在项目中的哪个位置。我从Finder中将其拖到Assets文件夹中,但仍然找不到。我查看了类似的问题,但答案是在旧版本的 Xcode 中,并没有解决我的问题。我使用的是 Xcode 11.1
if let filepath = Bundle.main.path(forResource: "BibleTable", ofType: "csv") {
do {
let contents = try String(contentsOfFile: filepath)
print(contents)
} catch {
print("Error reading file BibleTable.csv")
}
} else {
print("File not found")
}
它给出“找不到文件”
最佳答案
只要您的应用程序(以及任何测试目标)在文件检查器的目标成员资格组件中被选为目标,即可在 Bundle 中除 Assets 文件夹之外的任何位置进行操作。
关于ios - 项目中的哪个位置适合放置要在 iOS 应用程序中读取的资源文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58765157/