1

Say for example In Xcode I make 3 folders in my supporting files older named "a" "b" and "c".

In each of these folders I have an xml file name "file.xml".

How can I use NSMainBundle to get paths to these 3 different xml files?

dubbeat
  • 7,706
  • 18
  • 70
  • 122

1 Answers1

2

To get these files at runtime Xcode will copy them in the Copy Bundle Resource phase. This normally copies into the root of the bundle. To deal with directories see @CocoaFu's answer to this SO question.

Then in the code

NSBundle* bundle = [NSBundle mainBundle] will give you the main bundle

From this you look in directories using pathForResource:ofType:inDirectory: e.g.

NSString* path = [bundle pathForResource:@"file.xml" 
                                  ofType:nil 
                             inDirectory:@"a"];

The methods are given in NSBundle class reference also see the Bundle Programming guide

Community
  • 1
  • 1
mmmmmm
  • 32,227
  • 27
  • 88
  • 117