为什么我不能从我的 XCode 项目中删除文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4875836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can't I delete files from my XCode project?
提问by jowie
This is probably a very easy question, but I'm having trouble deleting resources from my XCode project. I added them using "Create Folder References for any added folders" so that I could import a whole offline HTML site with its correct folder structure.
这可能是一个非常简单的问题,但我无法从 XCode 项目中删除资源。我使用“为任何添加的文件夹创建文件夹引用”添加它们,以便我可以导入具有正确文件夹结构的整个脱机 HTML 站点。
Unfortunately, now it has been added like this I don't seem to be able to delete individual files in the structure (it's not available from the Edit menu).
不幸的是,现在已经像这样添加了我似乎无法删除结构中的单个文件(它不能从“编辑”菜单中使用)。
Can anyone help please? Thanks!
有人可以帮忙吗?谢谢!
采纳答案by Tomas
That isn't how folder references work. The idea is that its only a reference, you can open files within it and save it from those editors, you can delete or move the entire reference throughout the xcode project, but you can't actually edit it - its read only as far as xcode is concerned. Likewise, you cannot restructure it (move internal files around).
这不是文件夹引用的工作方式。这个想法是它只是一个参考,您可以在其中打开文件并从这些编辑器中保存它,您可以在整个 xcode 项目中删除或移动整个参考,但您实际上无法编辑它 - 它的只读xcode 关注。同样,您无法对其进行重组(移动内部文件)。
I'm not to sure why apple decided to make this the case, but apparently they have.
我不确定为什么苹果决定这样做,但显然他们已经这样做了。
If you want to know how one might use the xcode folder system, here's how I tend to use them with my projects:
如果你想知道如何使用 xcode 文件夹系统,下面是我倾向于在我的项目中使用它们的方式:
Whenever I subdivide code into folders, when I drag them into my project I click "recursively create groups for any added folders". If you do this, you any changes you make within xcode will not reflect the actual file itself. As far as I know, there is no way to do this. What does happen then is that when you add a new code file to it, the directory starts off in that file by default. ie, you don't need to navigate to it manually when you create a new file.
每当我将代码细分为文件夹时,当我将它们拖到我的项目中时,我都会单击“为任何添加的文件夹递归创建组”。如果您这样做,您在 xcode 中所做的任何更改都不会反映实际文件本身。据我所知,没有办法做到这一点。然后会发生的是,当您向其中添加新代码文件时,默认情况下该目录从该文件中开始。即,您无需在创建新文件时手动导航到它。
I use folder references whenever I'm working with content for an application I'm using. This way, I add all my images, folders, configuration files, whatever - and xcode immediately lists them. The reason I have it within xcode, I can I copy the files into the executables directory by dragging the folder reference into a "Copy Files" build phase.
每当我处理正在使用的应用程序的内容时,我都会使用文件夹引用。通过这种方式,我添加了我所有的图像、文件夹、配置文件等等——并且 xcode 会立即列出它们。我在 xcode 中使用它的原因是,我可以通过将文件夹引用拖到“复制文件”构建阶段来将文件复制到可执行文件目录中。
Thats basically (to my knowledge) how one uses the folder types within xcode - sadly, I don't know how to achieve the functionality you want. You may have to manually delete the folders in finder, which if you do use folder references will update xcode to the change.
这基本上是(据我所知)如何在 xcode 中使用文件夹类型 - 遗憾的是,我不知道如何实现您想要的功能。您可能必须手动删除 finder 中的文件夹,如果您确实使用了文件夹引用,则会将 xcode 更新为更改。
回答by Jeff Hester
I ran into the same issue by using "Create Folder References for any added folders". I wanted to change some of the times but that's not possible. I had added a main folder that had other directories under it. I just had to select the main directory and deleted it and then just add the subdirectories that I needed. You can't make any location or removal changes to the directories that are added this way. -- Jeff
我通过使用“为任何添加的文件夹创建文件夹引用”遇到了同样的问题。我想改变一些时间,但那是不可能的。我添加了一个主文件夹,该文件夹下有其他目录。我只需要选择主目录并删除它,然后只需添加我需要的子目录。您不能对以这种方式添加的目录进行任何位置或删除更改。——杰夫
回答by Crashalot
I ran into the same issue. Delete the files from the folder directly as opposed to from within Xcode. You'll see the entries turn red under your project. Restarting Xcode should make these red entries vanish.
我遇到了同样的问题。直接从文件夹中删除文件,而不是从 Xcode 中删除。您将看到项目下的条目变为红色。重新启动 Xcode 应该会使这些红色条目消失。
回答by Dan Ray
In the project browser, where you're looking at files, right click and choose "Delete". It'll prompt you to either remove the file from the project (leaving the underlying file on the filesystem) or to also move the underlying file to the trash.
在您正在查看文件的项目浏览器中,右键单击并选择“删除”。它会提示您从项目中删除文件(将底层文件留在文件系统上)或将底层文件移至垃圾箱。