如何在 Xcode 中格式化代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6543026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:00:18  来源:igfitidea点击:

How to format code in Xcode?

xcodeformatkeyboard-shortcutscode-formatting

提问by James Raitsev

I wonder how can I format my code to align it neatly? Does it have a feature similar to Eclipse's ctrlshiftf?

我想知道如何格式化我的代码以使其整齐对齐?它是否具有类似于 Eclipse 的功能ctrlshiftf

回答by Piotr Kochański

Select firstthe text you want to format and then press Ctrl+I.

首先选择要格式化的文本,然后按Ctrl+ I

Use Cmd+Afirst if you wish to format all text in the selected file.

如果您希望格式化所选文件中的所有文本,请先使用Cmd+ A

Note: this procedure only re-indents the lines, it does notdo any advanced formatting.

注意:此程序仅重新缩进行,进行任何高级格式化。

回答by J. Costa

Key combination to format all text on open file:

用于格式化打开文件上的所有文本的组合键:

Cmd ?A+ CtrlI

Cmd ?A+ CtrlI

回答by Dair

  1. Select the block of code that you want indented.

  2. Right-click (or, on Mac, Ctrl-click).

  3. Structure → Re-indent

  1. 选择要缩进的代码块。

  2. 右键单击(或者,在 Mac 上,按住 Ctrl 键单击)。

  3. 结构 → 重新缩进

回答by superlogical

I would suggest taking a look JetBrains AppCode IDE. It has a Reformat Code command. I have come from a C# background and used Visual Studio with Jetbrains Resharper plugin, so learning AppCode has been a pleasure because many of the features in Resharper also exist in AppCode!

我建议看看 JetBrains AppCode IDE。它有一个重新格式化代码命令。我来自 C# 背景,使用 Visual Studio 和 Jetbrains Resharper 插件,所以学习 AppCode 是一种乐趣,因为 Resharper 中的许多功能也存在于 AppCode 中!

Theres too many features to list here but could well be worth checking out

此处列出的功能太多,但很值得一试