How do I completely rename an Xcode project (i.e. inclusive of folders)?
Step 1 - Rename the project
- Click on the project you want to rename in the "Project navigator" in the left panel of the Xcode window.
- In the right panel, select the "File inspector", and the name of your project should be found under "Identity and Type". Change it to your new name.
- When the dialog asks whether to rename or not rename the project's content items, click "Rename". Say yes to any warning about uncommitted changes.
Step 2 - Rename the scheme
- At the top middle of the window, to the left of the active device/simulator, there is a scheme for your product under its old name; click & hold on it, then choose "Manage Schemes…".
- Click on the old name in the scheme (similar to renaming files in Xcode) and it will become editable; change the name and click "Close".
Step 3 - Rename the folder with your assets
- Quit Xcode. Rename the master folder that contains all your project files.
- In the correctly-named master folder, beside your newly-named .xcodeproj file, there is probably a wrongly-named OLD folder containing your source files. Rename the OLD folder to your new name (if you use Git, instead, you could run
git mv oldname newname
to change the name, so that Git recognizes this is a move, rather than deleting/adding new files). - Re-open the project in Xcode. If you see a warning "The folder OLD does not exist", dismiss the warning. The source files in the renamed folder will have red names because the path to them has broken.
- In the "Project navigator" in the left-hand panel, click on the top-level folder representing the OLD folder you renamed.
- In the right-hand panel, under "Identity and Type", change the "Name" field from the OLD name to the new name.
- Just below that field is a "Location" menu. If the full path has not corrected itself, click on the nearby folder icon and choose the renamed folder. You may have to perform this fix for each source file if the links to them remain broken.
Step 4 - Rename the Build plist data
- Click on the project in the "Project navigator" on the left, and in the main panel select "Build Settings".
- Search for "plist" in the settings.
- In the Packaging section, you will see fields for
Info.plist
andProduct Bundle Identifier
. - If there is a file name entered in
Info.plist
, update it (it may have been updated automatically in Step 1). - Do the same for
Product Bundle Identifier
, unless it is utilizing the ${PRODUCT_NAME} variable. In that case, search for "product" in the settings and updateProduct Name
. IfProduct Name
is based on ${TARGET_NAME}, click on the actual target item in the TARGETS list on the left of the settings pane and edit it, and all related settings will update immediately. - Search the settings for "prefix" and ensure that
Prefix Header
's path is also updated to the new name. - If you use SwiftUI, search for "Development Assets" and update the path. Enclose in double-quotes (
""
) quotes if the path contains a space ( - If you have an entitlements file, search for "signing" and update
Code Signing Entitlements
. Accordingly, rename the actual entitlements file in the Project Navigator also. (Side note: In Xcode 13 entitlements files have a yellow checkmark icon in the Project Navigator; you may have created one if e.g. you use shared containers/App Groups.)
Step 5 - Repeat step 3 for tests (if you have them)
Step 6 - Repeat step 3 for core data if its name matches project name (if you have it)
Step 7 - Clean and rebuild your project
- Command + Shift + K to clean
- Command + B to build
Further points.
- If the project has storyboards.
At this stage, open the folder in finder and type the old name in the file text search. You will see that the old name appears very often as customModule="OldName"
in all storyboard files. (Explanation.) These can be fixed one by one by tapping on the module drop down under Custom Class in the inspector. However in practice you'll likely want to change them all with a global replace in each storyboard file, perhaps using a plain text editor.
To add to luke-west's excellent answer:
When using CocoaPods
After step 2:
- Quit Xcode.
- In the master folder, rename
OLD.xcworkspace
toNEW.xcworkspace
.
After step 4:
- In Xcode: choose and edit
Podfile
from the project navigator. You should see atarget
clause with the OLD name. Change it to NEW. - Quit Xcode.
- In the project folder, delete the
OLD.podspec
file. rm -rf Pods/
- Run
pod install
. - Open Xcode.
- Click on your project name in the project navigator.
- In the main pane, switch to the
Build Phases
tab. - Under
Link Binary With Libraries
, look forlibPods-OLD.a
and delete it. - If you have an objective-c Bridging header go to Build settings and change the location of the header from OLD/OLD-Bridging-Header.h to NEW/NEW-Bridging-Header.h
- Clean and run.