xcode 文件无法复制到 Project

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8172918/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:27:40  来源:igfitidea点击:

File couldn't be copied to Project

iphoneiosxcode

提问by Yashwanth Kumar

I have just started making a test app , here is what happened.

我刚刚开始制作一个测试应用程序,这是发生了什么。

  1. I copied some files in to my project.

  2. deleted them, as reference only.

  3. I tried to add them again,

  1. 我将一些文件复制到我的项目中。

  2. 删了,仅供参考。

  3. 我试着再次添加它们,

and i get the following error

我收到以下错误

" randomfile.h couldn't be copied to TestApp because an item with same name already exists "

“ randomfile.h 无法复制到 TestApp 因为同名的项目已经存在“

randomfile.h is the file i am trying to add and TestApp is the project name.

randomfile.h 是我要添加的文件,TestApp 是项目名称。

How can i add the same file again?

如何再次添加相同的文件?

回答by Matt H

Un-select the "Copy items into destination if needed" checkbox. Are you adding the file from and to the same folder? If it's from a different folder, then you need to rename or delete the one that you had before.

取消选中“如果需要,将项目复制到目的地”复选框。您是否在同一文件夹中添加文件?如果它来自不同的文件夹,那么您需要重命名或删除以前的文件夹。

回答by ColdLogic

It worked, but i don't understand why this happened, can you explain in detail?

它有效,但我不明白为什么会发生这种情况,您能详细解释一下吗?

You deleted the items by reference only, that means that you only deleted the projects reference to it, essentially, removing it from the project, but not deleting it from disk. So the file is still on your hard drive in your project files directory. Trying to copy another instance of it will be like trying to copy 2 files with the same name into the same directory, thus you get the "because an item with same name already exists" error

您仅通过引用删除了项目,这意味着您只删除了对它的项目引用,实质上是将其从项目中删除,而不是从磁盘中删除它。因此该文件仍在您的硬盘驱动器上的项目文件目录中。尝试复制它的另一个实例就像尝试将 2 个具有相同名称的文件复制到同一目录中一样,因此您会收到“因为具有相同名称的项目已经存在”错误

回答by Shaun Neal

However, this doesn't work if you delete folders. Here are steps to reproduce:

但是,如果您删除文件夹,这将不起作用。以下是重现步骤:

Add a folder called "images".

添加一个名为“图像”的文件夹。

In that folder, add a folder called "test".

在该文件夹中,添加一个名为“test”的文件夹。

Put a couple of files in the test folder.

将几个文件放在 test 文件夹中。

Delete the test folder. Select "move to trash" (as opposed to delete references).

删除测试文件夹。选择“移至垃圾箱”(而不是删除引用)。

Try to add a "test" folder into the images folder by dragging in from finder.

尝试通过从 finder 中拖入将“test”文件夹添加到图像文件夹中。

Error by OP appears - xcode does not delete folders (or subfolders) when you select the move to trash option, even when you have that folder selected. You have to manually remove the folders from finder.

出现 OP 错误 - 当您选择移至垃圾箱选项时,即使您选择了该文件夹,xcode 也不会删除文件夹(或子文件夹)。您必须手动从 finder 中删除文件夹。

回答by Sean Chen

Go to project directory to find and delete the file that has the same name as the one you were trying to copy to project

转到项目目录以查找并删除与您尝试复制到项目的文件同名的文件