[SOLVED]Path to plist is null but I can't figure out why.

Discussion in 'iOS Programming' started by chrono1081, Jul 23, 2014.

  1. chrono1081, Jul 23, 2014
    Last edited: Jul 23, 2014

    chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #1
    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.
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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.
     
  3. chrono1081 thread starter macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #3
    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).
     
  4. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #4
    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.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
  6. chrono1081 thread starter macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar

Share This Page