Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode duplicates files in project

Tags:

xcode

ios

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.

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)

like image 808
MichelleJS Avatar asked May 21 '13 22:05

MichelleJS


People also ask

How do I duplicate files in Xcode?

In XCode 4.2 (I know this is an old question) there is Duplicate under the File menu. Select the file (you can select multiple files but it doesn't appear to do anything useful) in the Project Navigator and then File->Duplicate. Hooray!

Can you duplicate an Xcode project?

Duplicating an Xcode ProjectIn the Finder, duplicate the project folder to the desired location of your new project. Do not rename the . xcodeproj file name or any associated folders at this stage. In Xcode, rename the project.


2 Answers

Try this instead:

  1. Highlight all the duplicate files
  2. Right click on one of the files and press "Delete"
  3. When prompted for which delete option, click "Remove Reference"
like image 159
Abdou Sarr Avatar answered Oct 21 '22 00:10

Abdou Sarr


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.

When you add files as a copy, the Xcode project navigator shows added files with an A and modified files with an M.

Modified and Added files

If the file is inside a closed group folder, the folder shows an A.

Added file copy inside closed group folder

If you add a reference without a copy the project navigator won't show an A but MyApp.xcodeproj will show 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.

discard changes

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, a gui for git

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://git-scm.com/doc (scroll down to see videos)

http://www.sourcetreeapp.com

http://gitimmersion.com

like image 2
beepscore Avatar answered Oct 20 '22 23:10

beepscore