codereviewanskquestions
codereviewanskquestions

Reputation: 13998

Objective C, Can not load xml file stored in resources folder in xcode

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDicrectory = [paths objectAtIndex:0];
 NSString *filePath = [documentsDicrectory stringByAppendingPathComponent:@"libdata.xml"];
 NSString *xmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];

I stored an xml file (not small about 140k size) in resources folder in xcode and tried to load the xml file to parse it. But xmlString gets nil. What is wrong with this code? Thanks in advance

Upvotes: 0

Views: 1370

Answers (1)

Macmade
Macmade

Reputation: 54020

Use the NSBundleClass:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html

NSString * filePath = [ [ NSBundle mainBundle ] pathForResource: @"libdata" ofType: @"xml" ];

Upvotes: 2

Related Questions