Tuesday, 25 September 2012

XCode: Renaming classes, variables, methods, files

More often than not I give my classes stupid names or use unconventional capitalisation when writing code.  I have painfully crawled through code changing names by hand before but not only is that time-consuming it's very error prone.  XCode has a facility to quickly fix bad names without breaking your build.  It's called refactoring.

To rename the class ReallyStupidClassName (or anything else within your project's build) select that text somewhere and choose Refactor->Rename... from the Edit menu.

Type in the new name to replace all instances of ReallyStupidClassName and click Preview to see all changes to be made before committing.

Once you're content with the changes to be made click on save and the changes are all done.  So much easier than trawling through by hand.

Thanks to Devin's old post on this subject.