美文网首页swift
swift3 Bundle.main.path获取本地文件路径失

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

作者: 红姑娘 | 来源:发表于2017-12-21 15:04 被阅读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

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/jvdawxtx.html