swift: Bundle.main.path 返回 nil

Gin*_*nso 4 xcode swift

我在我的资产中创建了一个名为“json”的文件夹,我从查找器中拖放了一个名为 code.json 的文件。现在我想打开该文件但是

Bundle.main.path(forResource: "code", ofType: "json", inDirectory: "json")
Run Code Online (Sandbox Code Playgroud)

刚刚返回nil

我还尝试将其放入没有子文件夹的资产中并使用以下方式

Bundle.main.path(forResource: "code", ofType: "json")
Run Code Online (Sandbox Code Playgroud)

得到相同的结果。

谁能帮我?我究竟做错了什么?

Sh_*_*han 7

当你把它拖到xcode时,你需要做文件夹引用,它的颜色是蓝色而不是黄色

在此输入图像描述

//

在此输入图像描述