Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSBundle pathForResource is NULL

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] (null)

And I don't know why.

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

like image 497
patrick Avatar asked Oct 16 '10 14:10

patrick


1 Answers

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

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.

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.

like image 133
DarkDust Avatar answered Oct 12 '22 10:10

DarkDust