How To Rename An Xcode Project

# Filed on May 16, 2009 by AnthonyDiSante 5 replies

When you’re using Xcode to develop an iPhone app or a Mac app, you might decide that you need to rename your project.  In many cases this would mean not only renaming the actual executable file that gets produced, but also the names of various source code files, project folders, and the contents of various files within the project.

As far as I can tell, Xcode provides no way to do this.  There are a few settings that seem like they might do part of it, but every time I tried to use one of them within Xcode, it just resulted in errors and my project failing to build.  After many hours and much frustration with Xcode, I decided to try it the Unix way, and it worked.  The solution is a straightforward 3-step process:

1. First I closed Xcode, and made a backup of my project folder.  Then I went into my project folder and renamed every file and folder which contained "OldName" so that it now contained "NewName" instead.  This could be scripted pretty easily but my current project is a small one so I spent the ~5 minutes to manually rename the files and folders.

2. In the project folder, I ran the following command in a terminal, to update the contents of the files in the project:

find . -type f -exec sed -i 's/OldName/NewName/g' "{}" \;

3. I opened the now-renamed project in Xcode and clicked Build -> Clean All Targets.

After that, the project (with the new name) built successfully.

Comments:

01. Jan 6, 2010 at 09:49pm by PaulMasson:

Brilliant! Works like a charm with one modification: for Mac OS X Leopard, you must specify an empty extension with the -i switch, or the stream editor will return an "invalid command code" message.

02. Apr 2, 2010 at 12:59am by MikeTheCat:

OK, that sounds nice, but those of us who are new to the Mac/OSX don’t know the command syntax to "specify an empty extension" with the -i switch.  I’ve also seen some reference to need for the -e switch when using -i, but that might not apply here.

Can you show the modified command to include the "empty extension"?

03. Apr 2, 2010 at 02:54am by MikeTheCat:

Other info, such as on forums macosxhints com, suggest that all of these should work in Leopard.

find . -type f -exec sed -i "" ’s/OldName/NewName/g’ "{}" \;

find . -type f -exec sed -i "" -e ’s/OldName/NewName/g’ "{}" \;

find . -type f -exec sed -i -e ’s/OldName/NewName/g’ "{}" \;

find . -type f -exec sed -ie ’s/OldName/NewName/g’ "{}" \;

Can anybody confirm if which of those, if any, will work?

04. Apr 2, 2010 at 07:43am by AnthonyDiSante:

If you run the command "man sed" you’ll see the sed manual, which explains how the -i switch works.  Here’s a quote:

-i extension: Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given, no backup will be saved.

So just plain -i, or -i followed by empty quotes, will probably both work the same; either way should be fine.

05. Apr 2, 2010 at 02:13pm by MikeTheCat:

The post from Jan 6 suggested that the -i by itself doesn’t work in Leopard without the "" to specify the empty extension, but thanks for the additional lead to the full information.  This will help me form the habit of using that tool.

Reply to this message here:

Your name
Email (why?)
Website (if you have one)
Subject
search posts:

home | archives ]