.json 文件未包含在 mainBundle 中?
我正在创建一个 iPhone 应用程序,其中包含资源中的 .json
文件,但无法使用以下方式访问这些文件:
[[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"json"]
似乎这些文件不包含在构建的应用程序包中。我需要配置什么才能在包中包含 .json 文件吗?
谢谢
I'm creating an iPhone app that includes .json
files in the resource, but those files couldn't be accessed using:
[[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"json"]
It seems that these files aren't included in the built app-package. Is there something i have to configure to include .json files in the package?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没什么可做的,只是检查它是否已添加到目标中(图中右侧的小勾号)。然后检查构建详细信息日志以验证它已被有效复制。
Nothing to do, just checking it has been added in the target (the small tick on the right in the picture). And then check the build details logs to verify it has been effectively copied.
添加 XCode 11 的更新屏幕截图,介绍如何使用鼠标右键单击访问“文件检查器”以及如何打开“目标成员资格”(屏幕右下角)。我花了太长时间试图解决这个问题
Adding an updated screenshot for XCode 11 on how to access "File Inspector" using right mouse click and how to turn on "Target Membership" (Bottom right on the screen). I spent far too long trying to work this one out
只需确保您在目标中包含 .json 文件即可。您可以通过检查目标中的资源复制阶段来检查它是否已复制到主包。如果该文件列在那里,那么它也包含在您的捆绑包中。
Just make sure you include the .json file in the target. You can check if it is copied to your main bundle by inspecting the Resource Copy phase in the target. If the file is listed there, then it's also included in your bundle.