How to use code formatter in Xcode for Swift?

2020-05-16 15:18发布

Xcode code formatter Swift

I'm trying to auto format my code written in Swift. It's necessary if you're working in team and using CVS and don't want to merge for hours.

Ctrl+I just makes an indent, but for example i want to have proper space between functions and just all the stuff like in Clang.

9条回答
冷血范
2楼-- · 2020-05-16 15:48

The reformat code command in xcode is Ctrl-I, not Cmd-I and it appears to work just fine.

查看更多
家丑人穷心不美
3楼-- · 2020-05-16 15:48

+i: reformat code
Ctrl+i: fix code indentation

Eventhough it has good IntelliSense, xcode sucks at code formatting generally.
Wish it was better.
Apple has to spend so much effort in this in order to make it VS level good.

查看更多
够拽才男人
4楼-- · 2020-05-16 15:53

SwiftFormat is a popular code formatter for swift. It has an extension for Xcode, which can be accessed from the Editor menu.

Quote from the SwiftFormat readme:

SwiftFormat is a code library and command-line tool for reformatting swift code on macOS or Linux.

SwiftFormat goes above and beyond what you might expect from a code formatter. In addition to adjusting white space it can insert or remove implicit self, remove redundant parentheses, and correct many other deviations from the standard Swift idioms.

查看更多
登录 后发表回答