Reputation: 18191
I have a project named XXX
. I want to rename this project to YYY
.
Note that XXX
is an extremely common term (for e.g. "data", or simply "project"), and thus a simple RegEx search-and-replace is not possible, out of risk of corrupting the project configuration files.
My current project directory contains the following items:
XXX
XXXTests
XXX.xcodeproj
and I want to rename them to:
YYY
YYYTests
YYY.xcodeproj
... respectively, with the necessary changes being reflected in my project file.
How can I accomplish this without having to manually create and populate a new project?
Edit: It is absolutely ridiculous that this has become my most upvoted question.
Upvotes: 719
Views: 303131
Reputation: 15033
Note: for Xcode 14, Sept. 2022: in some cases Xcode now automatically renames the scheme, when Xcode performs Step 1 above. If so, there is nothing to do in Step 2.
git mv oldname newname
. Note that when using git mv old new
you generally must (i) completely commit all other changes (ii) only then git mv old new
(iii) commit that (iv) only then make further changes. If steps i-ii-iii-iv are followed, git will maintain history through the rename.}Info.plist
and Product Bundle Identifier
.Info.plist
, update it (it may have been updated automatically in Step 1).Product Bundle Identifier
, unless it is utilizing the ${PRODUCT_NAME} variable. In that case, search for "product" in the settings and update Product Name
. If Product 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.Prefix Header
's path is also updated to the new name.""
) quotes if the path contains a space (
).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.)Further points.
At this stage, open the overall folder simply in the Mac finder. 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, in Xcode, one by one, on each storyboard: Tap on the view controller in the file inspector, and be sure to tap on the actual storyboard in the white column on the left of the actual storyboard panel. Tap on the Identity Inspector (4th small button) in the right hand panel. Look at the Custom Class -> Module field. Notice it seemingly shows NewName in gray. However (still as of Xcode14.2) it is incorrect. Simply tap the drop-down, and explicitly select the new name. (If you now review that storyboard file with a text editor, you will see it is fixed.) You may prefer to change them all just using a plain text editor.
Upvotes: 1465
Reputation: 933
Extra instructions when following @Luke-West's + @Vaiden's solutions:
Also, I did not have to use step 3 of @Vaiden's solution. Just running rm -rf Pods/
in terminal got rid of all old pod files
I also did not have to use step 9 in @Vaiden's solution, instead I just removed the OLD project named framework under Link Binary Libraries (the NEWLY named framework was already there)
So the updated steps would be as follows:
Step 1 - Rename the project
Step 2 - Rename the Scheme
Step 3 - Rename the folder with your assets
Step 4 - Rename the Build plist data
Step 5 Handling Podfile
pod deintegrate
You should be able to build with no errors after you have followed all of the steps successfully
Upvotes: 11
Reputation: 117
If its react native what you can do is: You can change the name attribute in package.json, run react-native upgrade, and just let react overwrite the android/ios files. Don't overwrite your index files if there is unsaved code, however.
Upvotes: 0
Reputation: 155
I find helpful few simple steps I found on web:
Upvotes: 0
Reputation: 73
One more thing to note that I don't think has been noted yet is if you are using CoreData objects along with a lazy persistentContainer
in the AppDelegate file (or anywhere else), you may get an error saying NSManagedObjectContext is nil (or something along those lines). Change the name for any NSPersistentContainer to use the NEW app name. That should fix the issue! If not, according to this old SO post the solution is to delete your old .xcdatamodeld
file and create a new one adding back all the entities again.
Upvotes: 0
Reputation: 6236
There is a GitHub project called Xcode Project Renamer
:
It should be executed from inside root of Xcode project directory and called with two string parameters: $OLD_PROJECT_NAME & $NEW_PROJECT_NAME
Script goes through all the files and directories recursively, including Xcode project or workspace file and replaces all occurrences of $OLD_PROJECT_NAME string with $NEW_PROJECT_NAME string (both in each file's name and content).
Upvotes: 40
Reputation: 1423
Please cd
to a non-Git repository before proceeding ⚠️
/NewProjectFolder
Outside your Git repository. ⚠️ changes to .git could corrupt your git index 💥 ☠Now we're going to rename the project from oldName
to NewProject
.
Close Xcode.
Go to your /NewProjectFolder
.
cd /Path/to/your/NewProjectFolder
Install the extra tools needed.
brew install rename ack
Rename the files and directories containing the source string. You’ll need to run this command twice, because directories will be renamed first, then files and directories inside those will be renamed on the next iteration.
find . -name 'oldName*' -print0 | xargs -0 rename --subst-all 'oldName' 'NewProject'
Check if all the files containing the source string are renamed. You should see empty output.
find . -name 'oldName*'
Replace all occurrences of the string in all files.
ack --literal --files-with-matches 'oldName' --print0 | xargs -0 sed -i '' 's/oldName/NewProject/g'
Check if all occurrences of the string in all files were replaced. You should see empty output.
ack --literal 'oldName'
Run pod install
Add NewProjectFolder
to your repository.
You are done!
Upvotes: 77
Reputation: 343
To change the project name;
Select your project in the Project navigator.
In the Identity and Type section of the File inspector, enter a new name into the Name field.
Press Return.
A dialog is displayed, listing the items in your project that can be renamed. The dialog includes a preview of how the items will appear after the change.
To selectively rename items, disable the checkboxes for any items you don’t want to rename. To rename only your app, leave the app selected and deselect all other items.
Press "Rename"
Upvotes: 8
Reputation: 16132
To add to luke-west's excellent answer:
OLD.xcworkspace
to NEW.xcworkspace
.Podfile
from the project navigator. You should see a target
clause with the OLD name. Change it to NEW.OLD.podspec
file.rm -rf Pods/
pod install
.Build Phases
tab.Link Binary With Libraries
, look for libPods-OLD.a
and delete
it.Upvotes: 235
Reputation: 6564
Xcode 11.0+.
It's really simple now. Just go to Project Navigator, the left panel of the Xcode window. Press Enter to make it active for rename, just like you change the folder name.
Just change the new name here, and Xcode will ask you for renaming other pieces of stuff.
Tap on Rename here and you are done.
If you are confused about your root folder name, like why it's not changed, well it's just a folder. It is just renamed it with a new name.
Upvotes: 88
Reputation: 1504
Adding to the accepted answer by Luke West. If you have any entitlements:
Upvotes: 3
Reputation: 2279
Aside from all the steps Luke and Vaiden recommended, I also had to rename all the customModule properties in my Storyboard to match the new name, and this has to be case sensitive.
Upvotes: 2