Does Xcode support regions?

后端 未结 8 1347
慢半拍i
慢半拍i 2020-12-06 04:15

Does Xcode support anything akin to Visual Studio style #region directives for arbitrary code folding?

相关标签:
8条回答
  • 2020-12-06 04:36

    A useful option in XCode 12 (maybe before), is an option in preferences "Code Folding Ribbon"

    When you check it, the source code looks like this

    When you hover the mouse over this ribbon, you get foldable regions based on brackets, like this

    When you click the Ribbon, it folds the bracket region, like this

    Its not as the regions in Visual Studio, where you can place them wherever you want, but they're good enough to tidy up your code files.

    0 讨论(0)
  • 2020-12-06 04:39

    I am going to hell for this but here goes:

    At the top of a given file, put

    #define FOLD 1
    

    Wherever you want to fold something, wrap it in an if block like so:

    if(FOLD) {
     // your code to hide
     // more code
    }
    

    That will let you fold it away out of sight.

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