#pragma mark not showing in methods in Xcode 4.0

前端 未结 13 1762
死守一世寂寞
死守一世寂寞 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:32

    I had this problem while using a syntax that used to work on xcode 3.x and does not work for xcode 4 anymore.

    I was using just "pragma"

    #pragma - My Pragma Text
    

    That used to work fine for xcode 3 but, for xcode 4, the complete syntax has to be used. This means that #pragma must always be followed by the "mark" keyword.

    #pragma mark - My Pragma Text
    

    EDIT

    Xcode 6 (fixed in beta 4) uses // MARK: syntax for swift files

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

    user1639164 - At the risk of being pedantic, I'd say you're "95%" correct. I found it is possible to get Xcode to display a pragma before your first method. If the first chunk of code in a source file happens to be a regular procedure rather than a method, then you will get the pragma showing up. E.g.

    NSString * localizedString (NSString * key)
    {
    // My code here…
    }
    
    # pragma mark - app-delegate startup
    
    - (id) init
    {
      self = [super init];
      if (self)… etc
    

    This is an extract from my boilerplate app delegate code. In this case, you will see the pragma show up before the first method. But not before your first chunk of code! :-) So it's as if the pragma parsing machinery can't get its ass in gear until it's seen at least one routine - method or otherwise. As you say, hope it's fixed soon.

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

    I realize there is probably a very small percentage of uses for whom what I'm about to say applies, but just in case...

    If you use Doxygen to generate documentation from your source code comments, and you tend to comment your methods in the implementation file (i.e. .m), then adding an empty section after @implementation will cause Doxygen to fail to parse your Doxygen comments.

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

    For marks within the methods (or anywhere else) you can now use keyword TODO: as comment.

    like this:

    // TODO: some text
    

    I'm not sure about xcode version this became available (probably 4.5+), but it's available in latest one.

    enter image description here

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

    Did #pragma marks work inside of methods in the previous xcode? I really would like to use them, but like you said, it only works in between methods but not within a method, which would be really useful.

    BUMP if anybody has any ideas on ways to achieve adding code to a section within a method that would add it to the XCode jump bar...

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

    And apparently, they will not work before your first method. This, for example, will not work:

    #import "Person.h"
    
    @implementation Person
    
    #pragma mark - Convenience
    
    // ===========================================================
    //           Class/Convenience Methods
    // ===========================================================
    
    + (Person *)personWithName:(NSString *)name hourlyRate:(double)rate
    {
        Person *person = [[[Person alloc] initWithName:name rate:rate] autorelease];
        return person;
    }
    

    If I am wrong, let me know, but I don't think I am. If this should work, I hope it gets fixed!!

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