Why this happens
Xcode projects store file references as relative paths from the project root. When you duplicate a project folder in Finder and rename the .xcodeproj file or source folders, Xcode loses track of those files because the paths no longer match. The project navigator shows red filenames, and builds fail with missing file errors. Additionally, scheme names, target names, and build settings like INFOPLIST_FILE and LIBRARY_SEARCH_PATHS still reference the old names, causing further issues.
The accepted Stack Overflow answer combines two approaches: using Xcode’s built-in rename feature (which updates most references automatically) followed by manual folder re-linking and build setting cleanup. An alternative method edits the .pbxproj file directly, but that risks corrupting the project if done incorrectly.
How to fix it
1. Duplicate the project folder in Finder
- Close the project in Xcode.
- In Finder, copy the entire project folder to the new location.
- Do not rename the
.xcodeprojfile or any subfolders yet.
2. Rename the project in Xcode
- Open the duplicated
.xcodeprojin Xcode. - Select the project root in the Project Navigator (blue icon at top).
- Open the Utilities pane (right sidebar), show the File Inspector (first tab).
- Change the Project Name field to the new name.
- Xcode presents a sheet listing all items it will rename (targets, schemes, source folders, prefixes). Keep all selected and click Rename.
This updates the project name, target names, scheme names, product name, and PRODUCT_NAME build setting. If your bundle identifier uses $(PRODUCT_NAME:rfc1034identifier), it updates automatically. Otherwise, update it manually in Signing & Capabilities.
3. Rename schemes and verify targets
- Click the scheme menu (next to the Stop button) → Manage Schemes.
- Slow-click the old scheme name and rename it to match the new project.
- Repeat for any additional schemes.
- Select each target in the project editor and verify the Display Name and Bundle Identifier are correct.
4. Build and test
Press ⌘B to build. The project should compile successfully at this point. The source folder in the Project Navigator still shows the old name, but file references work because Xcode tracks them by project-relative path.
5. Rename the source folder in Finder
- Close the project in Xcode.
- In Finder, rename the main source folder (the one containing
AppDelegate.swift,ViewController.swift, etc.) to match the new project name. - If you have test folders, rename those too.
6. Re-link the folder in Xcode
- Reopen the project. The folder in the Project Navigator appears red.
- Click the folder once to select it.
- In the File Inspector (Utilities pane), click the folder icon under Location (dark gray folder button).
- Navigate to the renamed folder in Finder and click Choose.
- Xcode re-associates all files inside; red names turn normal.
- Rename the virtual folder in the navigator to match (optional but tidy).
7. Update build settings referencing the old folder name
- Select the project root → Build Settings.
- Search for the old folder name.
- Common hits:
–INFOPLIST_FILE(e.g.,OldFolder/Info.plist→NewFolder/Info.plist)
–PREFIX_HEADER/GCC_PREFIX_HEADER(e.g.,OldFolder/Prefix.pch)
–LIBRARY_SEARCH_PATHS(third-party SDK paths)
–FRAMEWORK_SEARCH_PATHS
–SWIFT_INCLUDE_PATHS - Double-click each value and replace the old folder name with the new one.
- Repeat for each target (targets can override project-level settings).
8. Clean and build again
- Product → Clean Build Folder (⇧⌘K).
- Build (⌘B) and run (⌘R) to verify everything works.
Alternative: Direct .pbxproj editing (advanced)
If you prefer a single search-and-replace:
- Backup the project folder.
- Close Xcode.
- Right-click
.xcodeproj→ Show Package Contents. - Open
project.pbxprojin a text editor (VS Code, BBEdit). - Search for the old folder name and replace with the new one globally.
- Save, reopen in Xcode, clean and build.
Warning: The
.pbxprojfile is a property list in OpenStep format. A malformed edit can make the project unreadable. Always keep a backup.
How to prevent it
- Use File → Duplicate in Xcode for small changes; it handles renaming internally.
- Adopt a consistent folder naming convention from project creation.
- Keep
INFOPLIST_FILEandPREFIX_HEADERpaths relative to$(SRCROOT)instead of hard-coded folder names. - Store third-party library paths in
LIBRARY_SEARCH_PATHSusing$(SRCROOT)/Vendorrather than absolute paths. - Commit the working project to git before renaming; you can always
git checkoutif something breaks.
FAQ
Can I rename the .xcodeproj file itself in Finder?
No. Renaming the .xcodeproj file in Finder breaks the project because the internal project.pbxproj references the old filename. Always rename via Xcode’s Project Navigator as described in step 2.
What if my project uses CocoaPods or Swift Package Manager?
CocoaPods: After renaming, run pod install again. The Pods project and workspace references update automatically. Swift Package Manager: No extra steps needed; package dependencies are resolved by URL, not local folder names.
Why do some files stay red after re-linking the folder?
Files added with “Copy items if needed” unchecked may reference absolute paths. Select each red file, open the File Inspector, click the folder icon, and re-point to the correct location. Alternatively, remove and re-add them with “Copy items” enabled.
Credits
This guide consolidates the accepted Stack Overflow answer by the community, with additional safety steps and modern Xcode UI terminology.
Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.