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.


1 个解决方案



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.

在構建階段,資源(例如XML文件)將復制到應用程序包中。您可以通過導航到Project Settings,然后是Build Phases選項卡,然后展開Copy Bundle Resources構建階段來查看復制文件的列表。

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).




粤ICP备14056181号  © 2014-2021 ITdaan.com