Rename or refactor files in Xcode

Is it possible to rename / reorganize a class file and rename the actual file on disk? If so, how can I do this?

+76
objective-c iphone xcode refactoring renaming
Jun 17 '10 at
source share
5 answers

The safest way to rename files is to refactor the class name with the Xcode "Refactor" command. Using this command, make sure your code is also updated wherever a file or class is specified (including NIB).

Right-click the class name in the interface file ( .h ), select Refactor->Rename , and Xcode will guide you through the process, allowing you to view the changes before you commit them.

More details:

Right-click the class name (after @interface ) and select "Refactor-> Rename". For example, right-click on the ViewController in this code:

 @interface ViewController : UIViewController 

enter image description here

Enter a new name for the class:

enter image description here

Xcode will let you see the changes before committing.

enter image description here

You can also highlight the class name and use the Xcode Edit->Refactor menu, or even match it with a key combination if you want.

If you really want to rename the file without affecting any code, click on the name in the "Navigator" panel (left panel), wait a second and click again. The name will be highlighted and you can enter a new one. You can also delete from the Navigator, rename the file to Finder and re-add it to your project.

+165
Jun 17 2018-10-17T00:
source share

Works for Xcode 4.2.1: select a file in the project navigator (the panel on the left is the default) and click [tab]

+50
Dec 22 '11 at 17:04
source share

By default, Xcode will rename the file when you rename it either in the file navigator (on the left side of the screen) or when using the inspector.

+3
Jun 17 '10 at 22:40
source share

If you renamed the file manually and used “Find and Replace” to rename the class name, make sure the file is added to “Compile sources in the phases of building your target”, as it will probably be deleted.

0
Sep 05 '13 at 13:33
source share

Choose Refactor-> Rename Answer nevan king also works fine on Xcode version 7.0 beta (7A120f)

0
Jun 17 '15 at 7:46
source share



All Articles