Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Svinja

macrumors newbie
Original poster
Oct 27, 2008
27
0
Hello, i need some xml files stored on iphone, is there any way i can include them to my app so they are available on iphone when the user installs my iApp. I know i can add images to project and then load them with +imageName
function but i need xml files and to be in specific directory. thx
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You can add any files you like to the resources of your application bundle and get access to the using the NSBundle methods as described in the documentation.
 

Svinja

macrumors newbie
Original poster
Oct 27, 2008
27
0
thx, there are two guide on apple for this actually, Bundle Programming Guide and Resource programming guide but i didnt find it with google.
For all n00bs like me, the solution is very simple:

Code:
// Get "News.xml" path from bundle
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"News" ofType:@"xml"];

this way you get file path which you can use in standard file routines.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
One thing you should be aware of is that you can't change files within your bundle (breaks the code signing). If you are intending updating that file copy it to your applications sandbox area on first run...
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
Yeah,you can't change the file in your bundle but you can access it. If you need to write files you need to locate your applications directory and most objects have a write function.

PHP:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"test.txt"];
[myArray writeToFile:documentsDirectory atomically:NO];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.