How to use code formatter in Xcode for Swift?

后端 未结 9 663
Happy的楠姐
Happy的楠姐 2021-01-31 07:25

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

相关标签:
9条回答
  • 2021-01-31 07:54

    In Xcode [Objective-C, Swift]:

    1) +A: highlight code

    2) +I: reformat code

    0 讨论(0)
  • 2021-01-31 07:55

    Select lines, then press Ctrl+I.

    0 讨论(0)
  • 2021-01-31 07:57

    Xcode and Swift 2.0: Per file, Cmd-A then Ctl-I. Ctl-I works for what is highlighted, Cmd-A highlights all. Just be careful not to accidentally delete all your source after the Ctl-A!

    0 讨论(0)
  • 2021-01-31 08:02

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

    0 讨论(0)
  • 2021-01-31 08:03

    +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.

    0 讨论(0)
  • 2021-01-31 08:06

    (I know the question says Xcode but) personally this is another reason to use AppCode alongside Xcode.

    While Xcode only fixes the indentation for Swift code, as mentioned in the question, AppCode at least handles spaces too. Somewhat relatedly it removes indents from empty lines by default.

    AppCode's Swift support definitely isn't perfect yet and you still need to check the code in both, but it's still worth it because of better navigation and things like this.

    0 讨论(0)
提交回复
热议问题