Fix: Duplicate and Rename Xcode Project Without Breaking File Links

Written by

in

Quick answer: Duplicate the project folder in Finder, then rename the project in Xcode’s navigator to update references automatically. Rename schemes and targets, update the bundle identifier if needed. For the source folder, rename it in Finder, then re-link it in Xcode’s File Inspector by clicking the folder icon and selecting the renamed folder. Finally, search build settings for old folder names in paths like Info.plist and Library Search Paths.

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

  1. Close the project in Xcode.
  2. In Finder, copy the entire project folder to the new location.
  3. Do not rename the .xcodeproj file or any subfolders yet.

2. Rename the project in Xcode

  1. Open the duplicated .xcodeproj in Xcode.
  2. Select the project root in the Project Navigator (blue icon at top).
  3. Open the Utilities pane (right sidebar), show the File Inspector (first tab).
  4. Change the Project Name field to the new name.
  5. 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

  1. Click the scheme menu (next to the Stop button) → Manage Schemes.
  2. Slow-click the old scheme name and rename it to match the new project.
  3. Repeat for any additional schemes.
  4. 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

  1. Close the project in Xcode.
  2. In Finder, rename the main source folder (the one containing AppDelegate.swift, ViewController.swift, etc.) to match the new project name.
  3. If you have test folders, rename those too.

6. Re-link the folder in Xcode

  1. Reopen the project. The folder in the Project Navigator appears red.
  2. Click the folder once to select it.
  3. In the File Inspector (Utilities pane), click the folder icon under Location (dark gray folder button).
  4. Navigate to the renamed folder in Finder and click Choose.
  5. Xcode re-associates all files inside; red names turn normal.
  6. Rename the virtual folder in the navigator to match (optional but tidy).

7. Update build settings referencing the old folder name

  1. Select the project root → Build Settings.
  2. Search for the old folder name.
  3. 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
  4. Double-click each value and replace the old folder name with the new one.
  5. Repeat for each target (targets can override project-level settings).

8. Clean and build again

  1. Product → Clean Build Folder (⇧⌘K).
  2. Build (⌘B) and run (⌘R) to verify everything works.

Alternative: Direct .pbxproj editing (advanced)

If you prefer a single search-and-replace:

  1. Backup the project folder.
  2. Close Xcode.
  3. Right-click .xcodeproj → Show Package Contents.
  4. Open project.pbxproj in a text editor (VS Code, BBEdit).
  5. Search for the old folder name and replace with the new one globally.
  6. Save, reopen in Xcode, clean and build.

Warning: The .pbxproj file 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_FILE and PREFIX_HEADER paths relative to $(SRCROOT) instead of hard-coded folder names.
  • Store third-party library paths in LIBRARY_SEARCH_PATHS using $(SRCROOT)/Vendor rather than absolute paths.
  • Commit the working project to git before renaming; you can always git checkout if 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.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.