Code Formatting In Xcode

前端 未结 12 1819
名媛妹妹
名媛妹妹 2020-12-09 02:01

Is there anyway to format the code in Xcode like you can do in Eclipse or Netbenas. I have not found any option in menu, is there any hot key for this or its simply not in X

相关标签:
12条回答
  • 2020-12-09 02:32

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

    You can bind this to a hotkey in the preferences.

    0 讨论(0)
  • 2020-12-09 02:38

    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

    0 讨论(0)
  • 2020-12-09 02:38

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

    0 讨论(0)
  • 2020-12-09 02:41

    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.

    0 讨论(0)
  • 2020-12-09 02:42

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

    Fix code indentation in Xcode

    0 讨论(0)
  • 2020-12-09 02:47

    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:

    • http://hackertoys.com/2008/09/18/adding-a-code-beautifier-script-to-xcode (dead link)
    • http://8020world.com/jcmendez/2006/11/geeky-stuff/software/adding-a-script-menu-to-xcode-to-reformat-code-using-astyle (dead link)
    0 讨论(0)
提交回复
热议问题