在 Xcode 中,有两种方式可以格式化代码:
-
使用快捷键:选择你想要格式化的代码后,按下
Control-I
或者选择Editor -> Structure -> Re-Indent
,Xcode 将会自动为你格式化代码。 -
使用自动格式化选项:在 Xcode 首选项的
Text Editing
标签下,勾选Automatically trim trailing whitespace
和Automatically format on save
的选项,Xcode 将会自动格式化你的代码。但是这种方式会导致所有的空格和换行符被删掉,所以不推荐使用。