Renaming xcode 4 project and the actual folder

Chris G. picture Chris G. · Nov 24, 2011 · Viewed 40.2k times · Source

I know how to rename the project in Xcode 4, but how do you rename the source folder? The thing is that renaming the project in Xcode, does only rename within Xcode (Though it is progress compared to previous) - but why Xcode is not renaming the folder in the filesystem I don't know.

Answer

Nick Lockwood picture Nick Lockwood · May 13, 2013

You can do this from within Xcode without resorting to hand editing the pbxproj file in a text editor!

Here's how:

  1. Rename your source folder in the Finder. This will break the project initially because Xcode doesn't automatically detect when the real folders that the virtual (yellow) project folders point to are changed, so all the files inside that folder will turn red in Xcode. Don't worry about that, we'll fix it in step 3.

  2. In Xcode, click on the (now broken) virtual folder in the left-hand sidebar and rename it to match the name in the Finder (you can actually call it anything you want, or not rename it at all, but that would be insane). That won't fix the red files inside the folder, but that's OK.

  3. In the right-hand sidebar in Xcode, click the icon shown in the screenshot below to bring up a file dialog. Select the folder that you previously renamed. This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside.

  4. In your build settings, search for the old folder name and manually rename any occurrences you find. There will typically be two of them, oldfolder/prefix.pch and oldfolder/info.plist, but there may be others.

All done!

enter image description here

EDIT: this option is still there in Xcode 5, but is helpfully hidden by default. To show it, click the thin "Identity and Type" header in the inspector above the "Text Settings" panel to expand it.