#pragma mark not showing in methods in Xcode 4.0

前端 未结 13 1760
死守一世寂寞
死守一世寂寞 2021-01-01 13:16

In Xcode Version 4.0 I notice that #pragma marks within methods are no longer showing up in the Jump Bar. The only #pragma marks that are showing up are those that are betwe

相关标签:
13条回答
  • 2021-01-01 13:25

    I'm also experiencing this problem. A pragma mark added before the first method will not show up. For example, this will not work:

    @implementation RandomClass
    
    #pragma mark - Getter Methods
    
    - (void) firstMethod
    {
    }
    
    @end
    

    Here are some quick-dirty workarounds to make the pragma mark before the first method show up. You can add an empty block before it or you can just put the pragma mark inside the block itself.

    Using an empty block:

    @implementation RandomClass
    {}
    #pragma mark - Getter Methods
    
    - (void) firstMethod
    {
    }
    
    @end
    

    Adding the pragma mark inside the empty block itself:

    @implementation RandomClass
    {
    #pragma mark - Getter Methods
    }
    
    - (void) firstMethod
    {
    }
    
    @end
    

    It doesn't look too pretty but it works. I hope that helps.

    0 讨论(0)
  • 2021-01-01 13:26

    To clarify the correct answer by RantriX…

    If your first #pragma mark fails to appear in the jump bar's context menu, add a pair of braces. (Xcode version 4)

    For example, change this:

    @implementation MainMenu
    
    #pragma mark Lifecycle
    

    to this (note the curly braces):

    @implementation MainMenu
    {
    
    }
    
    #pragma mark Lifecycle
    
    0 讨论(0)
  • 2021-01-01 13:27
    @implementation ViewController
    
    - (void)pragmaStartHack {} // Since pragma only works when after at least one method
    
    #pragma mark This pragma will render in Xcode
    
    // Your code here...
    
    @end
    
    0 讨论(0)
  • 2021-01-01 13:28

    I encountered the same problem. I now insert a dummy method after @implementation ... and before the first 'real' method. I define this method in the project's ...-Prefic.pch file so it does not show up in the Jump Bar.

    Add the following to your ...-Prefix.pch:

    #define PLEASE_LET_PRAGMA_MARK_WORK - (void) pleaseLetPragmaMarkWork {}
    

    And insert the request in your omplementations:

    @implementation anyClass
    
    PLEASE_LET_PRAGMA_MARK_WORK
    
    #pragma mark - This will show up.
    

    Works like a charm.

    0 讨论(0)
  • 2021-01-01 13:29

    Apparently there are some issues in the pragma parser in Xcode. In my case I could make the #pragmas re-appear by unificating their syntax to the new one.

    Instead of having not uniform and messy chunks of code with some pragmas in it:

    // Code ...
    #pragma mark -
    #pragma mark UITextViewDelegate Protocol
    
    // More code ...
    # pragma mark - Important stuff
    // Even more code ...
    

    I changed everything to:

    // Code ...
    
    #pragma mark - UITextViewDelegate Protocol
    
    // More code ...
    
    # pragma mark - Important stuff
    
    // Even more code ...
    

    Basically, I made sure...

    • there is one blank line before and after the #pragma line.
    • there is only one space before and another after the -.
    • the pragma line does not end with an space.

    UPDATE

    I've realized that sometimes above rules are not enough if the project is broken somewhere. ( I tried moving some sources to a new project and they showed correctly). So what I did is close my project, delete its derived data from the organizer and also delete these two folders

    MyProject.xcodeproj/project.xcworkspace/
    MyProject.xcodeproj/xcuserdata/
    

    So next time I open my project Xcode will re-generate them :)

    Now ALL my sources are OK again :)

    0 讨论(0)
  • 2021-01-01 13:31

    For showing pragma marks in Jump Bar try this :

    1. Just remove spaces between ' //MARK ' and ' : '.
    2. That should be like this ' //MARK: '.
    0 讨论(0)
提交回复
热议问题