在 Xcode 中,如何格式化代码?

3 min read

在 Xcode 中,有两种方式可以格式化代码:

  1. 使用快捷键:选择你想要格式化的代码后,按下 Control-I 或者选择 Editor -> Structure -> Re-Indent,Xcode 将会自动为你格式化代码。

  2. 使用自动格式化选项:在 Xcode 首选项的 Text Editing 标签下,勾选 Automatically trim trailing whitespaceAutomatically format on save 的选项,Xcode 将会自动格式化你的代码。但是这种方式会导致所有的空格和换行符被删掉,所以不推荐使用。