user3009729 user3009729 - 1 year ago 203
iOS Question

xcode (ios/objective c) access Supporting files

Please keep in mind this is my first ios app and first experience with xcode. I have researched this but i believe my inexperience is a key factor in not being able to find it.

I am creating an app for iPhone in xcode and need help locating a file. I am currently storing an xml file in the Supporting Files of xcode. I have searched through the directories using NSDirectory trying to locate it with no success.

Any help would be appreciated.

Answer Source

Resources, such as an XML file, are copied into the app bundle during the build phase. You can see the list of copied files by navigating to your Project Settings, then the Build Phases tab and then expanding the Copy Bundle Resources build phase.

To find resources that are copied into the bundle you can use NSBundle to get the path to the file:

[[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"xml"];

You can then use that path to load the XML file into a an NSData or NSString object before parsing it.

The directory structure inside an iOS app is largely flat, since most files are simply copied into the bundle ignoring the group structure that represents them in Xcode. It is possible to add folder references to Xcode that will be copied to the bundle verbatim, preserving their directory structure within the bundle, (look up the differences between Groups and Folder References in Xcode for more information).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download