swift - Bundle.main.path 返回 nil

标签 swift path null

当我尝试使用以下代码访问项目中的文件时,我不断收到 nil 路径:

let path: String
if let pathOfFile = Bundle.main.path(forResource: "comfortJH", ofType: "csv")
{
    path = pathOfFile
}
let stream = InputStream(fileAtPath: path)

I have checked my target memberships for the file.

I have also checked that it appears in "Copy Bundle Resources".

为什么会发生这种情况?

最佳答案

这是正确的目标成员(member)

enter image description here

关于swift - Bundle.main.path 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50476931/

相关文章:

android - 如何从设备获取所选视频的真实路径

ios - IBOutlet 在 drawRect 方法中为 nil

c - 如何使用英特尔 C 编译器为双函数返回 NULL?

android - 就像 Android 中的 AsyncTask 与 iOS 中的 AsyncTask 相同

ios - 使用 NSAttributedString 的 UILabel 的 NSForegroundColorAttributeName

swift - 单元测试时 waitForExpectations 上的 EXC_BAD_ACCESS

ios - 如何设计和设置 UICollectionView 的高度并防止其折叠?

node.js - 如何告诉 native Node.js 扩展在哪里可以找到(正确的)libstdc++?

html - 将css文件连接到html

mysql - mysql 日期返回空值和非空值