Bundle.main.path返回nil

时间:2018-05-22 21:50:32

标签: 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".

为什么会这样?

1 个答案:

答案 0 :(得分:0)

这是正确的目标memberShip

enter image description here