dubbeat
dubbeat

Reputation: 7847

How to Deal with Same named files in supporting files directory

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?

Upvotes: 1

Views: 962

Answers (1)

mmmmmm
mmmmmm

Reputation: 32671

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

Upvotes: 2

Related Questions