在Xcode中重命名或重构文件 [英] Rename or refactor files in Xcode

查看:744
本文介绍了在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?

推荐答案

重命名文件最安全的方法是使用重构类名Xcode的重构命令。使用该命令可确保您的代码也在引用文件或类(包括NIB)的任何位置更新。

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).

右键单击界面中的类名( .h )文件,选择重构 - >重命名,Xcode将引导您完成整个过程,在提交之前预览更改。

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.

更多详细信息:

右键单击在类名上(在 @interface 之后)并选择Refactor-> Rename。例如,在此代码中右键单击 ViewController

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

@interface ViewController : UIViewController

输入班级的新名称:

Xcode会让您查看提交前的更改。

Xcode will let you review the changes before you commit.

您还可以突出显示班级名称并使用Xcode的编辑 - >重构菜单,甚至可以映射如果需要,可以使用键盘快捷键。

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.

如果您确实要在不影响任何代码的情况下重命名文件,请单击导航器窗格(左侧窗格)中的名称,等待一秒钟,然后再次点击。该名称将突出显示,您可以键入一个新名称。您也可以从导航器中删除,在Finder中重命名该文件并将其重新添加到您的项目中。

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.

这篇关于在Xcode中重命名或重构文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆