Xcode source automatic formatting

后端 未结 19 626
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 16:10

As a C# developer, I have become highly dependent on the automatic formatting in Visual Studio 2008. Specifically, I will use the CTRL + K , D

相关标签:
19条回答
  • 2020-11-29 16:32

    I also feel xcode should have this function. So I made an extension to do it: Swimat

    Simple install by brew cask install swimat preview

    You can give it a try, see https://github.com/Jintin/Swimat for more information.

    0 讨论(0)
  • 2020-11-29 16:32

    Consider buying yourself a license for AppCode, an intelligent Objective-C IDE that helps iOS/OS X developers. AppCode is fully compatible with Xcode, but goes beyond Xcode in adding powerful features.

    AppCode an Objective-C variant of the Intellij IDEA IDE from JetBrains. They are also authors of popular ReSharper extension to Visual Studio, which main purpose from here seems like a desperate attempt to bring a touch of IDEA experience to a Microsoft product.

    AppCode is using its own code analyser which gives close-to-perfect refactoring and code navigation support. There is an ability to re-indent and completely reformat code also (although I still keep missing a couple of formatting settings in hard cases, but mostly it works well).

    You might try the trial version, of course.

    0 讨论(0)
  • 2020-11-29 16:35

    I suggest using ClangFormat. In order to install, please follow these steps:

    1. Install Alcatraz package manager for XCode Supports Xcode 5+ & OS X 10.9+
    2. After installation restart XCode.
    3. Open XCode -> Window Menu -> Package Manager
    4. Search (find) ClangFormat and install it. After installation again restart XCode.
    5. Now at XCode menu you can use Edit -> Clang Format submenu for formatting.

    You can choose different types of formatting. Also by enabling Format On Save you can gain auto-format capability.

    0 讨论(0)
  • 2020-11-29 16:36

    If your Xcode version 3.x , you should use "User Script" With Uncrustify , here this a Example:

    #!/bin/sh
    
    echo -n "%%%{PBXSelection}%%%"
    $YOURPATH_TO_UNCRUSTIFY/uncrustify -q -c $YOURPATH_TO_UNCRUSTIFY_CONFIG/CodeFormatConfig.cfg -l OC+
    echo -n "%%%{PBXSelection}%%%"
    

    add above to your Xcode "User Script".

    if Xcode version 4.x , I think you should read this blog : Code Formatting in Xcode 4,

    In this way , used the "Apple Services" , but it's not good enough , cause too slow experience, does anyone has the same thing ?

    why apple drop "user script" .... xD

    0 讨论(0)
  • 2020-11-29 16:38

    Unfortunately, Xcode doesn't have anything nearly as extensive as VS or Jalopy for Eclipse available. There are SOME disparate features, such as Structure > Re-Indent as well as the auto-formatting used when you paste code into your source file. I am totally with you, though; there definitely should be something in there to help with formatting issues.

    0 讨论(0)
  • 2020-11-29 16:38

    That's Ctrl + i.

    Or for low-tech, cut and then paste. It'll reformat on paste.

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