Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting data from the Info plist

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?

like image 979
Darren Avatar asked Mar 21 '12 13:03

Darren


People also ask

How do I read a plist file on a Mac?

plist - The primary property list for Mac OS X applications, located in the /​Contents/​ directory of an . APP bundle. To view this file, right-click an application file, select "Show Package Contents," and open the Contents folder.

What does Info plist contain?

The Info. plist file contains critical information about the configuration of an iOS mobile app—such as iOS versions that are supported and device compatibility—which the operating system uses to interact with the app. This file is automatically created when the mobile app is compiled.

How do I view info plist in XML?

You can see the XML version of the plist by opening the file in a text editor such as Sublime Text or Atom. *Edit - you can also right click the Info.


1 Answers

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.

like image 117
Damo Avatar answered Oct 12 '22 11:10

Damo