Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch rename my classes to change my project prefix?

I've created a project and built out a several model classes. I've decided that I'd like to recycle them as a separate framework. In doing so, I want to change my class prefix of those files. The issue is, of course, that I now have to batch rename my files and my classes. I could use the refactor tool, but I have tens of classes, so it would be tedious. Is there a good way to automate the process? For reference, I'm using Xcode 5.

like image 613
Moshe Avatar asked Oct 18 '13 01:10

Moshe


People also ask

How do you bulk rename files in Python?

To rename files in Python, use the rename() method of the os module. The parameters of the rename() method are the source address (old name) and the destination address (new name).

Can you batch change file names?

To batch rename files, just select all the files you want to rename, press F2 (alternatively, right-click and select rename), then enter the name you want on the first file. Press Enter to change the names for all other selected files.


1 Answers

For anyone looking for an answer, I think I have a solution, although it's something I'd like to see built in to Xcode. I've filed a radar.(#15261680)

I had three things to worry about here:

  1. The class names themselves. The class prefixes didn't match the framework that I wanted to put them in.

  2. The file names. Even if I did a careful global search and replace and changed the class prefixes, the file names would be wrong.

  3. The Xcode project references. Xcode keeps a list of your files, and I had to be sure that Xcode would know where to find my files, in the event that I renamed them.

What I did:

  1. I did a global search and replace. Instead of clicking "Replace All", I used the "Review" pane, so I was able to exclude about ten or so cases that I wanted to keep with the original prefix.

  2. I found a utility to do a batch rename. Now my files and classes all match nicely.

  3. Uh oh! Xcode doesn't know where my files are, now. To fix this, I opened the .pbxproj file and did another careful search and replace. (I made sure to quit Xcode first, so my changes wouldn't be overwritten automatically.)

This was a bit of an involved process, and I was hoping that there was a tool or Xcode feature to help me do this, but alas, not yet.

like image 109
Moshe Avatar answered Nov 15 '22 05:11

Moshe