简体   繁体   English

xcode(ios / objective c)访问支持文件

[英]xcode (ios/objective c) access Supporting files

Please keep in mind this is my first ios app and first experience with xcode. 请记住,这是我的第一个ios应用程序,也是我第一次使用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. 我正在xcode中为iPhone创建一个应用程序,需要帮助来查找文件。 I am currently storing an xml file in the Supporting Files of xcode. 我目前在xcode的支持文件中存储一个xml文件。 I have searched through the directories using NSDirectory trying to locate it with no success. 我已经使用NSDirectory搜索了所有目录,试图找不到它。

Any help would be appreciated. 任何帮助,将不胜感激。

Resources, such as an XML file, are copied into the app bundle during the build phase. 在构建阶段,将XML文件之类的资源复制到应用程序捆绑包中。 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获取文件的路径:

[[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文件加载到NSDataNSString对象中。

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. iOS应用程序内部的目录结构基本上是平坦的,因为大多数文件都被简单地复制到了包中,而忽略了用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). 可以向Xcode添加文件夹引用,该文件夹引用将原样复制到分发包中,并在分发包中保留其目录结构(有关更多信息,请在Xcode中查找“组”和“文件夹引用”之间的差异)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM