How do I completely rename an Xcode project (i.e. inclusive of folders)?

272

171

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 :p

Vatsal Manot

Posted 2015-10-27T14:06:26.117

Reputation: 8 323

Possible duplicate of Rename xcode project

– Ron Myschuk – 2015-10-27T16:47:46.513

Also asked and answered here http://stackoverflow.com/questions/17744319/duplicate-and-rename-xcode-project-associated-folders with 200 up votes on the answer

– Ron Myschuk – 2015-10-27T17:12:20.870

also asked and answered here http://stackoverflow.com/questions/8262613/renaming-xcode-4-project-and-the-actual-folder with 189 up votes both posts are still relevant in Xcode 7

– Ron Myschuk – 2015-10-27T17:13:04.903

If you just want to rename the app icon name, check this answer https://stackoverflow.com/questions/238980/how-to-change-the-name-of-an-ios-app

– LYu – 2017-06-15T04:13:55.607

Answers

669

Step 1 - Rename the project

  1. Click on the project you want to rename in the "Project navigator" on the left of the Xcode view.
  2. On the right select the "File inspector" and the name of your project should be in there under "Identity and Type", change it to the new name.
  3. Click "Rename" in a dropdown menu

Step 2 - Rename the Scheme

  1. In the top bar (near "Stop" button), there is a scheme for your OLD product, click on it, then go to "Manage schemes"
  2. Click on the OLD name in the scheme, and it will become editable, change the name

Step 3 - Rename the folder with your assets

  1. Quit Xcode
  2. In the correctly named master folder, there is a newly named xcodeproj file with the wrongly named OLD folder. Rename the OLD folder to your new name
  3. Reopen the project, you will see a warning: "The folder OLD does not exist", dismiss the warning
  4. In the "Project navigator" on the left, click the top level OLD folder name
  5. In Utilities pane under "Identity and type" you will see the "Name" entry, change this from the OLD to the new name
  6. Just below there is a "Location" entry. Click on a folder with the OLD name and chose the newly renamed folder

Step 4 - Rename the Build plist data**

  1. Click on the project in the "Project navigator" on the left, in the main panel select "Build Settings"
  2. Search for "plist" in this section
  3. Under packaging, you will see Info.plist, and Product bundle identifier
  4. Rename the top entry in Info.plist
  5. Do the same for Product Identifier

Finally, you are done and can rebuild (Command + Shift + K to clean, Command + B to build)

Luke West

Posted 2015-10-27T14:06:26.117

Reputation: 6 830

124

To add to @luke-west 's excellent answer:

When using CocoaPods

After step 2:

  1. Quit XCode.
  2. In the master folder, rename OLD.xcworkspace to NEW.xcworkspace.

After step 4:

  1. In XCode: choose and edit Podfile from the project navigator. You should see a target clause with the OLD name. Change it to NEW.
  2. Quit XCode.
  3. In the project folder, delete the OLD.podspec file.
  4. rm -rf Pods/
  5. Run pod install.
  6. Open XCode.
  7. Click on your project name in the project navigator.
  8. In the main pane, switch to the Build Phases tab.
  9. Under Link Binary With Libraries, look for libPods-OLD.a and delete it.
  10. 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
  11. Clean and run.

Vaiden

Posted 2015-10-27T14:06:26.117

Reputation: 8 945

19

A quicker solution using shell commands (works with CocoaPods too):

PLEASE cd TO A NON-GIT REPOSITORY BEFORE PROCEEDING ⚠️

Step 1 - Prerequisites

  1. Copy your original project folder to a temporary /NewProjectFolder OUTSIDE your git repository. ⚠️ changes to .git could corrupt your git index

Step 2 - Open Terminal

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!

Pietro Basso

Posted 2015-10-27T14:06:26.117

Reputation: 415

6

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).

Xcode Project Renamer

Olcay Ertaş

Posted 2015-10-27T14:06:26.117

Reputation: 2 158

5

To change the project name;

  1. Select your project in the Project navigator.

2.In the Identity and Type section of the File inspector, enter a new name into the Name field.

3.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.

  1. 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.

  2. Press "Rename"

Paal Aune

Posted 2015-10-27T14:06:26.117

Reputation: 115

3

Extra instructions when following @Luke-West's + @Vaiden's solutions:

  • If your scheme has not changed (still showing my mac) on the top left next to the stop button:

    1. Click NEWLY created Project name (next to stop button) > Click Edit Schemes > Build (left hand side) > Remove the old target (will say it's missing) and replace with the NEWLY named project under NEWLY named project logo

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

  1. Click on the project you want to rename in the "Project navigator" on the left of the Xcode view.
  2. On the right select the "File inspector" and the name of your project should be in there under "Identity and Type", change it to the new name.
  3. Click "Rename" in a dropdown menu

Step 2 - Rename the Scheme

  1. In the top bar (near "Stop" button), there is a scheme for your OLD product, click on it, then go to "Manage schemes"
  2. Click on the OLD name in the scheme, and it will become editable, change the name
  3. Quit XCode.
  4. In the master folder, rename OLD.xcworkspace to NEW.xcworkspace.

Step 3 - Rename the folder with your assets

  1. Quit Xcode
  2. In the correctly named master folder, there is a newly named xcodeproj file with the the wrongly named OLD folder. Rename the OLD folder to your new name
  3. Reopen the project, you will see a warning: "The folder OLD does not exist", dismiss the warning
  4. In the "Project navigator" on the left, click the top level OLD folder name
  5. In Utilities pane under "Identity and type" you will see the "Name" entry, change this from the OLD to the new name
  6. Just below there is a "Location" entry. Click on a folder with the OLD name and chose the newly renamed folder

Step 4 - Rename the Build plist data

  1. Click on the project in the "Project navigator" on the left, in the main panel select "Build Settings"
  2. Search for "plist" in this section Under packaging, you will see Info.plist, and Product bundle identifier
  3. Rename the top entry in Info.plist
  4. Do the same for Product Identifier

Step 5 Handling Podfile

  1. In XCode: choose and edit Podfile from the project navigator. You should see a target clause with the OLD name. Change it to NEW.
  2. Quit XCode.
  3. In terminal, cd into project directory, then: rm -rf Pods/
  4. Run pod install.
  5. Open XCode.
  6. Click on your project name in the project navigator.
  7. In the main pane, switch to the Build Phases tab. Under Link Binary With Libraries, look for the OLD framework and remove it (should say it is missing) The NEWLY named framework should already be there, if not use the "+" button at the bottom of the window to add it
  8. 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
  9. Clean and run.

You should be able to build with no errors after you have followed all of the steps successfully

itsmcgh

Posted 2015-10-27T14:06:26.117

Reputation: 93