swift

swift3 Bundle.main.path获取本地文件路径失

2017-12-21  本文已影响36人  红姑娘

使用swift的Bundle来获取项目的文件路径 , 代码如下:

    guard let jsonPath = Bundle.main.path(forResource: "MainVCSettings.json", ofType: nil) else {
        print("获取路径失败")
        return
    }
    print(jsonPath)

一直打印获取路径失败

解决方案:

打开build Phases中的 copy Bundle Resources点击下面的 + 添加需要获取的文件,重新运行就获取到路径了

添加文件.png
上一篇 下一篇

猜你喜欢

热点阅读