Code Formatting In Xcode

有些话、适合烂在心里 提交于 2019-11-28 07:25:05

Select some text and then: Edit->Format->Re-Indent

You can bind this to a hotkey in the preferences.

In Xcode 4, it's been moved to Editor > Structure > Re-Indent command (and has a default shortcut of CTRL+I ).

Dave DeLong

Other than re-indentation (Edit > Format > Re-Indent), not really. However, Xcode does have support for scripts (the menu to the right of the Window menu), so you could conceivably write a script that formats your code how you like it.

Edit: here are some links that touch on this subject:

geowar

My personal favorite code formatter is Uncrustify. It has many, many options, so I also suggest you download UniversalIndentGUI, a GUI to help set Uncrustify's behavior to your liking.

Here are the shortcuts, to format the code in Xcode

1.Format entire code (entire class/controller)

select the entire code and press +| on mac to format your code.

2.Format particular block of code

select the code and press

+] for right move and +[ for left move

Note : as per @JavierGiovannini sugesstion you can do using Editor Menu option

3.Select code --> Go to Editor --> Structure --> Re-Indent

Not saying this is best approach, but for completeness, if you cut and then paste the code back in, Xcode will automatically format it for you.

David DelMonte

In v.4 you can make some adjustments through xCode preferences...

Fix code indentation in Xcode

You can also highlight the code you want to re indent, and use the re-indent command

XCode 8 Extensions

Another option is to use an extension like Swimat. Does the job for me. However, the caveat is that it does not format on save due to the restrictive Xcode Extension APIs, but they're trying to find a workaround.

Ruth Vargas

Try this solution: ⌘A [⌘K ⌘F]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!