Working with Sample Code: Rename your project in Xcode 3.x

Posted by soychicka on Jul 18, 2009 in Uncategorized |

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:

  1. Make a copy of the folder containing the project, and rename it from OldProjectName to NewProjectName.
  2. I like to lock the OldProjectName folder to make sure I don’t accidentally muck up the original: (select OldProjectName folder, command-i, under General click the Locked checkbox.)  You can always undo it later.
  3. In the NewProjectName folder, rename:
    • OldProjectName.pch to NewProjectName.pch
    • OldProjectName.xcodeproj to NewProjectName.xcodeproj
    • OldProjectName-info.plist (if it exists) to NewProjectName-info.plist
  4. Delete the build folder.
  5. Right-click NewProjectName.xcodeproj and select Show Package Contents.
  6. Open project.pbxproj in your favorite text editor and do a find/replace to update all instances of OldProjectName to NewProjectName. (see #10 if any of your class files OldProjectName have in the filename.
  7. Open the project in Xcode.
  8. From the Build menu, select Clean all targets.
  9. 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.
  10. if any of your classes contain OldProjectName 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 @interface and @implementation declarations that contain OldProjectName to contain NewProjectName.
    • Build > Clean all targets again, 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…

Reply

Copyright © 2010 xocolatl. All rights reserved. Theme by Laptop Geek.