[英]Xcode Command-Line tool can't find pathForResource
I'm making an application that will take JSON and turn it into CoreData, basically copying: THIS 我正在制作一个将使用JSON并将其转换为CoreData的应用程序,基本上是在复制: THIS
My problem is that I think a change in Xcode has made it so that Command Line doesn't use NSBundle, and so using pathForResource always returns nil, and so I can't access my files in the Copy files part of Build Phases. 我的问题是我认为Xcode进行了更改,因此命令行不使用NSBundle,因此使用pathForResource始终返回nil,因此我无法在构建阶段的“复制文件”部分中访问文件。
Does anyone know how to access these files in a Command Line tool? 有谁知道如何在命令行工具中访问这些文件?
Any help would be greatly appreciated! 任何帮助将不胜感激!
Thanks 谢谢
Sam 山姆
PS. PS。 I've tried this solution to no avail.
我已经尝试过这种解决方案 ,但无济于事。
Use that: 使用:
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"filename" ofType:@"filetype"];
Instead of mainBundle. 代替mainBundle。 It works for UnitTests as well as standard builds.
它适用于UnitTests和标准构建。 "MainBundle" is only for phone builds.
“ MainBundle”仅适用于手机版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.