Reputation: 2330
In my application I am not able to get the plist using the below code. I am using Xcode 4.5 and here is my code for retrieving plist,
NSBundle *thisBundle = [NSBundle mainBundle];
NSDictionary *theDictionary;
NSString *commonDictionaryPath;
if (commonDictionaryPath = [thisBundle pathForResource:@"newfonts-Info" ofType:@"plist"])
{
theDictionary = [[NSDictionary alloc] initWithContentsOfFile:commonDictionaryPath];
}
Note:- If I try to retrieve a text or xml file then the above code works fine.
Upvotes: 0
Views: 709
Reputation: 2330
Finally I find the answer by self
I just open the documents directory and open the application.app file and got to see that the plist file which is shown as application-Info.plist
in the bundle is seen just as Info.plist
so I changed the above code and and retrieve the dictionary
NSString *commonDictionaryPath;
commonDictionaryPath=[[NSBundle mainBundle]pathForResource:@"Info" ofType:@"plist"];
NSDictionary *info=[NSDictionary dictionaryWithContentsOfFile:commonDictionaryPath];
NSLog(@"path %@",commonDictionaryPath);
Upvotes: 0
Reputation: 2453
Try this code
SArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString* fooPath = [[NSBundle mainBundle] pathForResource:@"newfonts-Info" ofType:@"plist"];
NSLog(fooPath);
contentArray = [NSArray arrayWithContentsOfFile:fooPath];
NSLog(@"%@",contentArray);
or this can also works with NSDictionary
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"newfonts-Info" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(@"%@",dict);
i hope it helps you.
Upvotes: 0
Reputation: 32066
To get the Info plist as a dictionary, you can just do:
NSDictionary *theDictionary = [[NSBundle mainBundle] infoDictionary];
Upvotes: 2
Reputation: 119031
Use
[[NSBundle mainBundle] infoDictionary];
Calling infoDictionary
on any bundle instance will return something (thought it may only contain private keys).
Upvotes: 1