Can you set code regions in Xcode?

前端 未结 6 1322
忘掉有多难
忘掉有多难 2020-12-31 01:03

When writing c#, in Visual Studio, you can set regions to group code accordingly. Being new to Xcode I can\'t seem to find a similar feature.

相关标签:
6条回答
  • 2020-12-31 01:13

    Using Xcode editor, you can collapse or expand any block of code by clicking in the little left margin. Moreover, you can put a mark in any point in the code with:

    #pragma mark your title as long as you want

    Your mark will then appear in the middle popup menu on top of the editor window.


    Update: I have found that a duplicate of this question exists here. The answers may be of interest.

    0 讨论(0)
  • 2020-12-31 01:17

    Sorry for being pedantic but it's "Xcode", not "X-Code".

    You can for example go:

    #pragma mark -
    

    or

    #pragma mark Initialization
    

    This will give you this kind of thing:

    0 讨论(0)
  • 2020-12-31 01:19

    Without support for .Net style regions, being able to collapse all your functions is the next best thing.

    command-option-shift-left arrow to collapse.

    command-option-shift-right arrow to expand.

    Xcode will remember the last state of collapsed functions.

    0 讨论(0)
  • 2020-12-31 01:31

    one more option

    #pragma mark - Initialization
    
    0 讨论(0)
  • 2020-12-31 01:32

    If you want to have a folding zone with a custom section of your code then put your desired code inside braces { }, and it will become a folding zone.

    But you have to keep in mind that braces also define variables scope, so this code should not have variables declarations which will be used outside these brackets.

    0 讨论(0)
  • 2020-12-31 01:33

    You can also use:

    // MARK: -
    

    or

    // MARK: Initialization
    

    which is more portable than #pragma mark.

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