Xcode is, for the most part, a fine IDE. But there are many things lacking. If you compare with Eclipse, for example, one of the big lacking aspects is refactoring.
Specific example: renaming a class is incredibly painful in Xcode. In Eclipse, you can rename a class and the file will be renamed, all the declarations will be modified, and all the uses of the class will be changed automatically. In Xcode, you have to do this by hand. This is even worse if you have used some of your classes in Interface Builder: some of the files it creates are binary, so things cannot be easily replaced there.
Read on for a partial workaround...
[robg adds: I can't test this one, lacking any real programming skills :) ... I also can't vouch for the problem itself...]
For Objective C and Xcode project files, it's easy to fix because they are all text files. Here's what I did:
Specific example: renaming a class is incredibly painful in Xcode. In Eclipse, you can rename a class and the file will be renamed, all the declarations will be modified, and all the uses of the class will be changed automatically. In Xcode, you have to do this by hand. This is even worse if you have used some of your classes in Interface Builder: some of the files it creates are binary, so things cannot be easily replaced there.
Read on for a partial workaround...
[robg adds: I can't test this one, lacking any real programming skills :) ... I also can't vouch for the problem itself...]
For Objective C and Xcode project files, it's easy to fix because they are all text files. Here's what I did:
- Open your project in Xcode and select "Clean all targets" in the Build menu.
- Quit Xcode.
- Make a full copy of your project directory, just in case.
- In a Terminal window, change into your project directory.
- For each class to rename, do this:
Note that the quotes surrounding the grep command are back ticks, not straight quotes.mv OldClass.m NewClass.m mv OldClass.h NewClass.h perl -p -i.bak -e 's/OldClass/NewClass/g' `grep -r OldClass .`
- The last command is doing textual substitution on all the files that contain the string OldClass. So make sure that the string does not appear somewhere you don't want to make the change. In particular, if the string is part of some other class or variable name that you do not want to rename, you will have problems.
- The perl command will leave the old version of each file on a file with the same name plus the extension .bak. You can use the diff command to see what changed, to make sure nothing unexpected got changed. For example:
You could also use the FileMerge application (from /Developer/Applications/Utilities) to show the differences in a prettier format.diff ChangedFile.m.bak ChangedFile.m - It will also replace the file name in the Xcode project file, so the next time you open your .xcode file, it should show up OK.
- Beware of binary files! One of the files produced by Interface Builder, keyedobjects.nib, is binary, and if you have used any of the classes you want to rename (for example, to link them into your interface), their names will probably be there. In this case, you can use the technique described above only if the two class names are of the same length. If this is the case, things will work fine (I did this several times).
- In any case, always make copies of the files before you modify them, and compare the files before and after each change, to look for unexpected substitutions.
•
[12,771 views]

