Home > database >  Unable to get xcode project to index appropriate directories
Unable to get xcode project to index appropriate directories

Time:10-23

So I had to delete my project and then reclone it from my repository, but when I clone down the project and I open it, other files from some time ago show in there, how is this possible?

Example this is the cloned directory:
enter image description here

But when I open the project, it shows this project structure:
enter image description here

Also it produces the following error when attempting to build the project:

Build input file cannot be found: '/Users/Development/Projects/MapGlider/Application/Utilities/Extensions.swift'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?

All help will be appreciated!

CodePudding user response:

The structure of the project as you see it in Xcode is a combination of file system information about your project in YourProject.xcodeproj/project.pbxproj file. So you have a mismatch between file system and that file, which is typically a result of inaccurate checkin (for example some changes were done directly in file system, and the project was not updated), or a bad merge (developer A did everything right, developer B, or even the same developer on a different branch, overrode those changes incorrectly).

So what you need to do is to fix those errors one by one.

Note: the steps below assume the project is in your control. If you are using some script or tool to generate the project, you will have to address those issues via that tool or script instead.

First, fix the project structure:

  1. Make sure Inspectors on the right side in Xcode are open. Choose File inspector tab
  2. Focus on a folder inside Xcode, and check Name, Location and Full Path of the folder. Especially notice the Full Path, if it's incorrect, change it to a correct one. Here's the example how. Repeat for all folders and files you want to have in the project
  3. Delete all folders and files you don't want to have in the project from Xcode. For example you can delete Extensions which appears as a file in your project, while it's actually a folder. Typically while deleting you should be able to delete them from file system as well if it exists, but if not, you can double check in file system and delete files / folders from there as well.
  4. Add folders and files missing from the project if needed. Follow Add existing files and folders to a project section in the linked page.

Once you cleaned up the project, you need to review / fix all your project targets:

To fix the Project targets

Try to build each target. If it succeeds, most likely everything is resolved (although watch out for runtime errors for resource files - so you may need to test your app to ensure nothing is missing too).

If building a target fails, you will need to see why. For example

  • if file is missing from the target, but you already added it to the Xcode project, you can add it to the target (see this page).
  • if file is missing from the target and is not visible in Xcode, go back to step 4 of the previous procedure and add those files to Xcode project, and then add them to the target
  • if a file is nowhere to find and is not needed, you can delete it from target. If it was needed, then... well, you have a problem and need to locate your missing code in your source repo or rewrite it.
  • Related