NSBundle pathForResource为NULL [英] NSBundle pathForResource is NULL

查看:84
本文介绍了NSBundle pathForResource为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xcode和objc创建一个简单的应用程序,我需要从文件加载NSDictionary,但是我无法使用NSBundle获取文件的路径:

I'm creating a simple application with xcode and objc and I need to load an NSDictionary from a file, but I can't get the path to the file using NSBundle:

NSString *l = [[NSBundle mainBundle] pathForResource:@"LoginStatuses" ofType:@"plist"];
NSLog(@"%@", l);

当我运行这段代码时,我得到了:

When I run this code I get this:

2010-10-16 10:42:42.42 Sample [5226:a0f](空)

2010-10-16 10:42:42.42 Sample[5226:a0f] (null)

我不知道为什么.

我创建了一个名为Resources的组,并在其中添加了LogingStatuses.plist:

I created a group called Resources and there I added the LogingStatuses.plist:

推荐答案

因此,在获得源代码之后,这是此问题的解决方案:

So here's the solution for this problem after I got the source:

我并没有真正注意所发布的屏幕截图,但是目标的类型为"命令行工具" ...,并且由于这些对象没有捆绑的[NSBundle mainBundle]课程返回零. Xcode并不抱怨它无法执行"复制捆绑资源"步骤,而只是默默地跳过了它,这是非常令人误解的.

I didn't really pay attention to the posted screenshot, but the target is of type "Command-line Tool"... and since those don't have a bundle [NSBundle mainBundle] of course returns nil. It's pretty misleading that Xcode doesn't complain that it can't execute the "Copy Bundle Resources" step, it just silently skips it.

解决方案仅是添加一个新目标,其类型为" Application ",从而生成基于捆绑软件的应用程序.然后选中此新目标的所有来源和资源的目标成员资格复选框.然后可以正确解析plist路径.

Solution is simply to add a new target, of type "Application" so a bundle-based application is generated. Then check the Target Membership checkboxes for all sources and resources for this new target. The plist paths are correctly resolved then.

这篇关于NSBundle pathForResource为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆