Today I had a unique xCode scenario crop up that caused multiple files in my project to appear as missing (red in the project file list). First, the scenario…the project is held in a git repo and development is done using a modified git-flow technique. As such we are often merging feature branches in to the develop branch and vice versa.
After merging the develop branch in to a feature branch and then returning to the develop branch numerous source files appeared as missing. I verified the files still existed on the filesystem, deleted the files from the project and added them back in with no change in file status in xCode, they still appeared missing. I then deleted them again, re-added them to the project (still missing) and then tried to adjust the location setting of each file to be "Relative to Project". This did not work either. I made another attempt to add the files and then manually select the location of each file in the filesystem. Although the files were there xCode still showed them as missing.
Seeing no other option than to re-create the project file by creating a duplicate project with a different name I came across a fix. I created the new project and then proceeded to move all of the header files in to one of the new project's sub directories via the Terminal. As soon as the header files were moved, all missing .cpp files in the original project showed up (file names turned to black from red). I then moved the header files back to their original location on the filesystem and my original project was back in business.
I do not know what the underlying cause of this corruption was, but in the end the fix was to move the files out of their original directory on the file system and then move them back. Hopefully this saves another developer time trying to figure out why xCode chose to incorrectly mark some files as missing