Getting data from the Info plist

23,628

Solution 1

From an earlier SO answer of mine. Attributes from the info.plist for your project are directly accessible by the following...

[[NSBundle mainBundle] objectForInfoDictionaryKey:key_name];

Your filePath is nil simply because it can't find the file - check spellings & check if the file you are trying to read from is actually in the bundle etc.

Solution 2

I do not think there is another way (unless it is the info.plist file then see Damo's comment), instead I would focus on figuring out why the filePath is nil, perhaps the plist file is no longer under target>build phases>copy bundle resources?

Solution 3

Replace

[[NSBundle mainBundle] pathForResource:@"FILE_NAME" ofType:@"plist"]

with

[[NSBundle mainBundle] pathForResource: @"Info" ofType: @"plist"]
Share:
23,628
Darren
Author by

Darren

Updated on July 31, 2022

Comments

  • Darren
    Darren almost 2 years

    Whenever I want to get data from a plist file I use the following code:

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"FILE_NAME" ofType:@"plist"];
    NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:filePath]; 
    

    But now I'm trying to read in data from the Info plist, and filePath is nil. Is there a different way to get data from the Info plist?