When I’m learning how to code in a new language, I like to start off some sample code that I know works, then mutilate it until it bears no resemblance to what the original developer came up with… but making sure that it still works at each step along the way.
But my adventures with Cocoa/Obj-C present a new challenge: no stand-alone php or perl files that can easily be shuffled and renamed… when you work with a language that requires the software be compiled, there’s a much deeper structure that needs to be modified in order to assign a new identity to the project.
Sadly, Xcode doesn’t have an option that allows you to create a new project from an existing project with a new name (note to Apple: this would be a great feature to include in 3.2, *wink wink nudge nudge*).
But in the meantime, when you have some sample code you want to play around with, but still hang on to the original and not muck up your hard drive with copies of copies of duplicates of copies… try this:
- Make a copy of the folder containing the project, and rename it from
1OldProjectName
to
1NewProjectName.
- I like to lock the
1OldProjectName
folder to make sure I don’t accidentally muck up the original: (select
1OldProjectNamefolder, command-i, under General click the Locked checkbox.) You can always undo it later.
- In the
1NewProjectName
folder, rename:
-
1OldProjectName.pch
to
1NewProjectName.pch -
1OldProjectName.xcodeproj
to
1NewProjectName.xcodeproj -
1OldProjectName-info.plist
(if it exists) to
1NewProjectName-info.plist
-
- Delete the build folder.
- Right-click
1NewProjectName.xcodeproj
and select Show Package Contents.
- Open
1project.pbxproj
in your favorite text editor and do a find/replace to update all instances of
1OldProjectNameto
1NewProjectName. (see #10 if any of your class files
1OldProjectNamehave in the filename.
- Open the project in Xcode.
- From the
1Build menu
, select
1Clean all targets.
- Try to build and see if it goes. If you’re working on an iPhone app, try it out in the simulator first… if you have any provisioning files for the old application name, you’ll have to go through the steps to create a new one before you can test it on your device.
- if any of your classes contain
1OldProjectName
in the class fileName, you’ll need to
- update the names of any .h/.m files that include the name of the project… don’t forget you’ll have to update import statements too
- rename any of the
1@interface
and
1@implementationdeclarations that contain
1OldProjectNameto contain
1NewProjectName.
-
1Build
>
1Clean all targetsagain, build again, and fix anything you missed.
You now have a fully renamed project, ready for mutilation. Enjoy!
Thanks to Aleksandar Vacić for posting this tutorial that I used to learn the basics of renaming a project…
No related posts.
Recent Comments