How to Deal with Same named files in supporting files directory
Say for example In Xcode I make 3 folders in m开发者_开发知识库y 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?
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
精彩评论