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.

請記住這是我的第一個ios應用程序和第一次使用xcode的經驗。我研究了這個,但我相信我的經驗不足是無法找到它的關鍵因素。

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.

我正在xcode中為iPhone創建一個應用程序,需要幫助找到一個文件。我目前正在xcode的支持文件中存儲一個xml文件。我使用NSDirectory搜索目錄,試圖找到它但沒有成功。

Any help would be appreciated.

任何幫助,將不勝感激。

1 个解决方案

#1


3  

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獲取文件的路徑:

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

然后,您可以在解析之前使用該路徑將XML文件加載到NSData或NSString對象中。

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

iOS應用程序內部的目錄結構基本上是扁平的,因為大多數文件都被簡單地復制到包中,而忽略了在Xcode中表示它們的組結構。可以向Xcode添加文件夾引用,這些文件將逐字復制到包中,保留其在包中的目錄結構(查看Xcode中組和文件夾引用之間的差異以獲取更多信息)。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



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