xcode 重复项目中的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16680360/
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
xcode duplicates files in project
提问by MichelleJS
I'm at a complete loss as to what I did to cause this: For the second time since I started using XCode about a month ago (my first time seriously using it after taking one class several years ago) I try to run my project and the next thing I know I have errors because I have duplicate references. I looked at the project and it appeared that most of the files in my project had duplicated themselves, however I discovered that they are not duplicate files just duplicate references. This happened to me today when I tried to build on an actual iphone for the first time but it also happened to me a few weeks ago while using the simulator. Neither time do I recall doing anything unusual. I have built and tested the project probably 100+ times and normally all goes ok. I was able to fix it the first time but I think I have made it worse this time and am probably going to add the files back into a new project. My co-worker also mentioned this happening to him (he has about as much experience with xcode as I do). He told me he ended up with files nested in folders (groups?) nested in other folders about 20 deep.
我完全不知道我做了什么导致这个:自从我大约一个月前开始使用 XCode 以来第二次(几年前我第一次认真使用它,几年前我第一次认真使用它)我尝试运行我的项目接下来我知道我有错误,因为我有重复的引用。我查看了该项目,似乎我的项目中的大多数文件都复制了自己,但是我发现它们不是重复文件,只是重复引用。今天我第一次尝试在实际的 iphone 上构建时发生了这种情况,但几周前在使用模拟器时也发生在我身上。我也不记得做过什么不寻常的事情。我已经构建和测试了该项目可能 100 多次,通常一切正常。我第一次能够修复它,但我认为这次我变得更糟了,并且可能会将这些文件重新添加到新项目中。我的同事也提到了这件事发生在他身上(他对 xcode 的经验和我一样多)。他告诉我他最终将文件嵌套在文件夹(组?)中,嵌套在其他文件夹中大约 20 深。
My question is this: Does anyone know what I may have done to cause this. I would really like to avoid this problem in the future since it is proving to be quite a headache. Any advice would be greatly appreciated.
我的问题是:有谁知道我做了什么导致这种情况。我真的很想在将来避免这个问题,因为事实证明它很头疼。任何建议将不胜感激。
E.T.A. xcode version 4.6.2 (possibly an earlier version the first time it happened)
ETA xcode 版本 4.6.2(可能是第一次发生时的早期版本)
回答by Abdou Sarr
Try this instead:
试试这个:
- Highlight all the duplicate files
- Right click on one of the files and press "Delete"
- When prompted for which delete option, click "Remove Reference"
- 突出显示所有重复文件
- 右键单击其中一个文件,然后按“删除”
- 当提示选择哪个删除选项时,单击“删除引用”
回答by beepscore
Also you asked for "any advice". If you aren't already using git source control in your Xcode projects, start now. You can spot many mistakes like this earlier and fix them more easily using git.
您还询问了“任何建议”。如果您尚未在 Xcode 项目中使用 git 源代码管理,请立即开始。您可以更早地发现许多类似的错误,并使用 git 更轻松地修复它们。
When you add files as a copy, the Xcode project navigator shows added files with an A and modified files with an M.
当您将文件添加为副本时,Xcode 项目导航器会显示添加的带有 A 的文件和带有 M 的修改后的文件。
If the file is inside a closed group folder, the folder shows an A.
如果文件位于封闭组文件夹内,则该文件夹显示 A。
If you add a reference without a copy the project navigator won't show an A but MyApp.xcodeproj will show M.
如果添加没有副本的引用,项目导航器不会显示 A,但 MyApp.xcodeproj 会显示 M。
In Xcode you can discard a change before committing it. In the case below, you would discard changes to all added or modified files.
在 Xcode 中,您可以在提交之前放弃更改。在下面的情况下,您将放弃对所有添加或修改的文件的更改。
Typically you review and commit changes frequently. Using a gui tool such as SourceTree, you have a good chance of spotting an accidental change before you commit. For example, you can see changes to the project file.
通常,您会经常查看和提交更改。使用诸如 SourceTree 之类的 gui 工具,您很有可能在提交之前发现意外更改。例如,您可以看到对项目文件的更改。
If you accidentally commit an unintended change, you can go back later and reverse a commit. By committing frequently, you have more control over which changes you undo and which ones you keep.
如果您不小心提交了意外更改,您可以稍后返回并撤消提交。通过频繁提交,您可以更好地控制撤消哪些更改以及保留哪些更改。
References:
参考:
http://www.raywenderlich.com/13771/how-to-use-git-source-control-with-xcode-in-ios-6
http://www.raywenderlich.com/13771/how-to-use-git-source-control-with-xcode-in-ios-6
http://git-scm.com/doc(scroll down to see videos)
http://git-scm.com/doc(向下滚动查看视频)
回答by Tim
I had the same 20 deep nesting of my main folder of images. If its not a bug its very strange behaviour. I just backed it all up !! Then I opened the folder in finder, found the point at which it was starting to nest and deleted it.
我的主图像文件夹也有同样的 20 个深度嵌套。如果它不是一个错误,它的行为非常奇怪。我只是备份了它!然后我在finder中打开文件夹,找到它开始嵌套的点并删除它。
I did a rebuild, but I don't think Xcode even noticed. It made no difference to the size of my app so Xcode was not putting unnecessary files in the binary.
我进行了重建,但我认为 Xcode 甚至没有注意到。它对我的应用程序的大小没有影响,因此 Xcode 不会将不必要的文件放入二进制文件中。
回答by A Fader Darkly
This happened to me when I imported a file. Suddenly I had two nested directories containing what looked like copies of all my files. The compiler complained about duplicate classes.
当我导入文件时,这发生在我身上。突然间,我有两个嵌套目录,其中包含我所有文件的副本。编译器抱怨重复的类。
I found a solution, but it's a ball-ache and a time sink.
我找到了一个解决方案,但它是一个球痛和一个时间槽。
1: Click on your project in the navigator to open up the project settings in the main view.
1:在导航器中单击您的项目以在主视图中打开项目设置。
2: Open the 'Compile Sources' accordion entry. (This allows you to see which files are being used in the compilation process.)
2:打开“编译源”手风琴条目。(这使您可以查看编译过程中正在使用哪些文件。)
3: Find any duplicates in here and delete them. (At this stage your project should compile again.)
3:在这里找到任何重复项并删除它们。(在这个阶段,您的项目应该再次编译。)
4: In your navigator view, slow-double-click one of the files that's duplicated there. This should allow you to rename it. Change the name (not the extension) slightly.
4:在您的导航器视图中,缓慢双击那里复制的文件之一。这应该允许您重命名它。稍微更改名称(不是扩展名)。
5: You should notice that the copy becomes red. Select it and hit delete. (This avoids the delete operation removing the file from the 'Compile Sources')
5:您应该注意到副本变为红色。选择它并点击删除。(这避免了从“编译源”中删除文件的删除操作)
6: Rename the original file back to its original name again.
6:将原来的文件重新改回原来的名字。
7: Repeat from 4 until done, or until bored.
7:从4重复直到完成,或者直到无聊。
8: Explain to your boss why a simple copy change took half a day.
8:向你的老板解释为什么一个简单的副本更改需要半天时间。
This process can be optimised up by first renaming all duplicated files, then deleting the duplicates all at once. However this means that you can't test for successful compilation between steps, which allows you to narrow the culprit down to a single file. And takes even more time.
可以通过首先重命名所有重复文件,然后一次性删除所有重复文件来优化此过程。但是,这意味着您无法在步骤之间测试是否成功编译,这使您可以将罪魁祸首缩小到单个文件。并且需要更多时间。
If compilation fails, ensure all the files you need are still in the 'Compile Sources' section, as this process can cause them to be lost from there. The compiler will normally give some reasonable errors about missing classes and variables, but a missing AppDelegate will produce a more confusing error.
如果编译失败,请确保您需要的所有文件仍在“编译源”部分中,因为此过程可能会导致它们从那里丢失。编译器通常会给出一些关于缺少类和变量的合理错误,但缺少 AppDelegate 会产生更令人困惑的错误。