Search code examples
.netxcodeprojectappdelegateworkspace

My Xcode workspace missing files such as AppDelegate, main.storyboard etc.


My Xcode Project (the blue copy) still has everything but my Xcode workspace (the white copy) is missing files such as AppDelegate, main.storyboard etc. I was trying to figure out how to completely change the name of the project and I think accidentally deleted the files in the workspace in the process. I was wondering if there was a way to get all my projects files back into a workspace so I can continue editing my app.


Solution

  • It's still a bit unclear what your Xcode workspace looks like or what you did that led to that, but I'm going to answer based on what you said that the files still exist, they just aren't "connected" anymore to your Xcode project.

    By default, the Xcode workspace only contains references to the actual files. If you tried deleting them, there's an option to remove just the reference (default) or move the actual files to trash. If you were trying to rename your project, you probably also renamed the project folder (also renames the actual folder in Finder) so the Xcode reference would now be invalid (would should show up as red).

    What you can do now is to add the files back to the workspace. On the project navigator on the left side, right-click on the project (blue icon) then select "Add Files to <your project>:

    Add Files

    That will open-up a Finder dialog to let you find a missing file:

    Add Files -> Add AppDelegate

    Select the file then Add. Repeat this for all the missing files to add them back again. Make sure that one of the build targets in "Add to targets" at the lower half of the dialog is checked.

    Then do a Clean and Build.

    After fixing your workspace, another thing you can do is to make sure all your files are set to "Relative to Group". You can set this at the "Identity and Type" section on the right-side panel.

    Relative to Group

    The next time the project folder gets renamed, the files that are under that folder would just show up as red, which means Xcode knows that those files belong to the workspace but it can't find the actual files. (This is what normally happens, I really don't know what caused your files to be removed).

    If you were trying to rename your project, this SO post provides an excellent step-by-step instructions: How do I completely rename an Xcode project (i.e. inclusive of folders)?

    Lastly, setup source control.
    This kind of problem can usually be resolved by reverting your changes.

    Good luck!