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

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

    to

    1
    NewProjectName

    .

  2. I like to lock the
    1
    OldProjectName

    folder to make sure I don’t accidentally muck up the original: (select

    1
    OldProjectName

    folder, command-i, under General click the Locked checkbox.) You can always undo it later.

  3. In the
    1
    NewProjectName

    folder, rename:

    • 1
       OldProjectName.pch

      to

      1
      NewProjectName.pch
    • 1
       OldProjectName.xcodeproj

      to

      1
      NewProjectName.xcodeproj
    • 1
      OldProjectName-info.plist

      (if it exists) to

      1
      NewProjectName-info.plist
  4. Delete the build folder.
  5. Right-click
    1
    NewProjectName.xcodeproj

    and select Show Package Contents.

  6. Open
    1
    project.pbxproj

    in your favorite text editor and do a find/replace to update all instances of

    1
    OldProjectName

    to

    1
    NewProjectName

    . (see #10 if any of your class files

    1
    OldProjectName

    have in the filename.

  7. Open the project in Xcode.
  8. From the
    1
    Build menu

    , select

    1
    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
    1
    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
      1
      @interface

      and

      1
      @implementation

      declarations that contain

      1
      OldProjectName

      to contain

      1
      NewProjectName

      .

    • 1
      Build

      >

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

Bookmark and Share

No related posts.


All comments of post - "Working with Sample Code: Rename your project in Xcode 3.x":

:Haha! I'am the first! Yeh~

Thank you!

Add a Comment / Trackback url

Comment begin from here or jump up!