Xcode 有代码自动格式化功能吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2243348/
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 03:16:53  来源:igfitidea点击:

Does Xcode have code autoformat feature?

iphonexcode

提问by sashaeve

Is any way to autoformat a source code in the Xcode IDE?

有什么方法可以在 Xcode IDE 中自动格式化源代码?

回答by Jasarien

There isn't really an autoformat option in Xcode.

Xcode 中并没有真正的自动格式化选项。

There is an option ^I(Control-I) to re-indent the code, which will re-align the code according to the tab width set in your preferences, but that's about as far as it goes.

有一个选项^I(Control-I) 可以重新缩进代码,它会根据您的首选项中设置的选项卡宽度重新对齐代码,但也就到此为止了。

You might have better luck with a text editor like TextMate? I don't know for certain, but I know it supports Objective-C and has some macros, there may be a reformat option?

使用像 TextMate 这样的文本编辑器可能会更好?我不确定,但我知道它支持 Objective-C 并有一些宏,可能有重新格式化的选项?

回答by Artem Kalachev

Yes Xcode 4 has an autoformat feature.

是的,Xcode 4 具有自动格式化功能。

Try following:

尝试以下操作:

  1. Select text. CMD+A.
  2. Press CTRL+I.
  1. 选择文本。CMD+ A
  2. CTRL+ I

Please also see here: Fix code indentation in Xcode

另请参阅此处: 修复 Xcode 中的代码缩进

回答by Paul R

One trick is to select the code (either "select all" or just the section you want to re-format) - then cut, then paste it back. This triggers the automatic code formatting in the Xcode editor.

一个技巧是选择代码(“全选”或仅选择要重新格式化的部分)-然后剪切,然后将其粘贴回去。这会触发 Xcode 编辑器中的自动代码格式化。

回答by Yiyue Wang

ctrl + I will auto format the code you're selecting

ctrl + 我会自动格式化你选择的代码

回答by chancyWu

ClangFormat-Xcodeis an Xcode plugin available in Alcatraz. This is a nice code format tool.

ClangFormat-Xcode是 Alcatraz 中可用的 Xcode 插件。这是一个很好的代码格式工具。

回答by netniV

I found that the Copy & Paste method (Cmd-A then Cmd-C then Cmd-V) worked in XCode 4 and was the method I used whilst I was waiting for google to display the results (Mac was going slow!)

我发现复制和粘贴方法(Cmd-A 然后是 Cmd-C 然后是 Cmd-V)在 XCode 4 中有效,是我在等待 google 显示结果时使用的方法(Mac 运行缓慢!)

回答by Indra

To change, go to xCode => Preferences => Text Editing => Indentation => Automatically indent based on syntax.

要更改,请转到 xCode => 首选项 => 文本编辑 => 缩进 => 根据语法自动缩进。

enter link description here

在此处输入链接描述