Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,811
5,751
Isla Nublar
Hi guys,

I'm testing a plist in a blank project and the code and plist setup is identical to my main project. It works perfectly in my main project, it does not work in my test project and I can't figure out why.

The only difference is my main project is iOS, the test project is only command line using Foundation.

Here is the code I have:

Code:
        NSArray *codes;
        
        NSString *path = [[NSBundle mainBundle]pathForResource:@"Codes" ofType:@"plist"];
        
        NSLog(@"%@", path); //This is null!
        NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path];

My plist was added to my project with the target of the project name and it is named "Codes.plist".

Is there some fundamental difference between command line and iOS projects that could be causing this? I have the same exact code in another project and it works just fine.

Anyone know why this may be null? I even tried creating a new plist and it doesn't work either. It's in the same spot in the directory as my working projects plist too.
 
Last edited:
This question is arguably in the wrong forum since you're talking about a Mac command-line application.

But anyway, the most direct answer to your question is that command-line applications aren't bundles. They are standalone executables. Therefore, you can't really include other files in your 'bundle' because there is no bundle for command-line apps.
 
This question is arguably in the wrong forum since you're talking about a Mac command-line application.

But anyway, the most direct answer to your question is that command-line applications aren't bundles. They are standalone executables. Therefore, you can't really include other files in your 'bundle' because there is no bundle for command-line apps.

Oh that's interesting I'm not too familiar with how the whole bundle thing works. Not many books cover that in depth.

Thank you for the explanation. (And sorry, I didn't think about it being a base mac app).
 
Typical (non command-line) Mac Apps and iPhone Apps are "bundles". Directories with several files including an executable, metadata, and other supporting files. You can see this by selecting a Mac App in Finder and doing the action "Open as Folder". Or you can use the command-line in Terminal. If you go to a directory with Mac apps, you'll see each one is a directory.

A command-line application is just the executable part.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.