Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

iphone - Rename or refactor files in Xcode

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The safest way to rename files is to refactor the class name using Xcode's "Refactor" command. Using that command makes sure that your code is also updated anywhere that references the file or the class (including NIBs).

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

More details:

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

@interface ViewController : UIViewController

enter image description here

Enter the new name for the class:

enter image description here

Xcode will let you review the changes before you commit.

enter image description here

You can also highlight the class name and use Xcode's Edit->Refactor menu, or even map it to a keyboard shortcut if you want.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...